mixer.cpp
4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "mixer.h"
Mixer::Mixer(string mVideo, string sVideo, int ssVideo, int psVideo, int tsVideo,
string id, string pathTemp, string pathContents) {
this->mainVideo = mVideo;
this->secondaryVideo = sVideo;
this->sizeSVideo = ssVideo;
this->positionSVideo = psVideo;
this->transpSVideo = tsVideo;
this->transparency = ""; //Por enquanto, a transparência esta desativada.
this->pathTempFiles = pathTemp;
this->pathMixedVideo = pathContents;
this->userID = id;
PRINTL(util::_DEBUG, "Mixer Done!\n");
}
Mixer::~Mixer() {
PRINTL(util::_DEBUG, "Mixer finalized!\n");
}
void Mixer::setPathOfFiles() {
this->pathTempFiles.append("/").append(this->userID);
this->pathMixedVideo.append("/").append(this->userID).append(".mp4");
cout << "PATH TEMP FILES: " << this->pathTempFiles << endl;
cout << "PATH MIXED VIDEOS: " << this->pathMixedVideo << endl;
}
/* O valor da largura e altura está na unidade de Pixels.
* Se o valor da variável for -1, deverá manter a proporção da mesma em relação
* à outra.
* Ex.: 600:-1 ==> largura é 600 e a altura será calculada em relação à mesma para
* manter proporção.
* Ex.: -1:600 ==> altura é 600 e a largura será calculada em relação à mesma para
* manter proporção.
*/
void Mixer::setSVSize() {
string tempTextFile = this->pathTempFiles;
tempTextFile.append("/").append("tamanho.txt");
cout << "TEMPTXT: " << tempTextFile << endl;
string ffprobeSentence = "ffprobe -show_streams "+this->mainVideo+" 2> /dev/null | grep \"height=\" | cut -d'=' -f2 > "+tempTextFile;
system(ffprobeSentence.c_str());
string strHeight = "324"; //Se não conseguir ler do arquivo a altura será essa...
ifstream arq(tempTextFile.c_str()); //Abrindo arquivo com info. dos vídeos
if (arq.is_open()) {
getline(arq,strHeight); //Lendo o tamanho(altura) do vídeo
arq.close();
}
int height = atoi(strHeight.c_str());
stringstream alt;
stringstream larg;
switch(this->sizeSVideo){
case SMALL:
this->widthSVideo = -1;
this->heigthSVideo = (0.3*height);
larg << this->widthSVideo;
larg >> this->widthStr;
alt << this->heigthSVideo;
alt >> this->heigthStr;
break;
case MEDIUM:
this->widthSVideo = -1;
this->heigthSVideo = (0.4*height);
larg << this->widthSVideo;
larg >> this->widthStr;
alt << this->heigthSVideo;
alt >> this->heigthStr;
break;
case LARGE:
this->widthSVideo = -1;
this->heigthSVideo = (0.5*height);
larg << this->widthSVideo;
larg >> this->widthStr;
alt << this->heigthSVideo;
alt >> this->heigthStr;
break;
default: //Se não escolheu nenhum inteiro válido, consideramos MEDIUM como o tamanho padrão.
this->widthSVideo = -1;
this->heigthSVideo = (0.4*height);
larg << this->widthSVideo;
larg >> this->widthStr;
alt << this->heigthSVideo;
alt >> this->heigthStr;
PRINTL(util::_WARNING, "Tamanho do vídeo de libras é inválido! Tamanho padrão selecionado.\n");
}
}
void Mixer::setSVPosition() {
switch(this->positionSVideo){
case TOP_LEFT:
this->positionStr = "10:10";
break;
case TOP_RIGHT:
this->positionStr = "main_w-overlay_w-10:10";
break;
case BOTTOM_RIGHT:
this->positionStr = "main_w-overlay_w-10:main_h-overlay_h-10";
break;
case BOTTOM_LEFT:
this->positionStr = "10:main_h-overlay_h-10";
break;
default: //Se não escolheu nenhum inteiro válido, consideramos BOTTOM_RIGHT como a posição padrão.
this->positionStr = "main_w-overlay_w-10:main_h-overlay_h-10";
PRINTL(util::_WARNING, "Posição do vídeo de libras é inválido! Posição padrão selecionada.\n");
}
}
void Mixer::initialize() {
setPathOfFiles(); //Tem que aparecer antes de setSVSize();
setSVSize();
setSVPosition();
mixVideos();
}
void Mixer::mixVideos() {
PRINTL(util::_INFO, "Mixando...\n");
string ffmpegSentence = "ffmpeg -i "+this->mainVideo+" -v quiet -y -vf \"movie="+this->secondaryVideo+", "+
"scale="+ this->widthStr +":"+this->heigthStr+", setpts=PTS-STARTPTS, [movie] overlay"+this->transparency+"="+this->positionStr+
" [out]\" -qscale 0 -strict experimental -vcodec libx264 -preset fast -r 30 -threads "+NUMTHREADS+" "+this->pathMixedVideo;
cout << "FFMPEG: " << ffmpegSentence << endl;
system(ffmpegSentence.c_str());
}