胡斌

parsing rotation=180 in record file,rotate the video when merge audio video

@@ -33,6 +33,7 @@ public: @@ -33,6 +33,7 @@ public:
33 int index; 33 int index;
34 media_type m_type; 34 media_type m_type;
35 int channel; 35 int channel;
  36 + int rotate; //degree,0,90,180 ...
36 }; 37 };
37 38
38 class media_info { 39 class media_info {
@@ -41,6 +42,7 @@ public: @@ -41,6 +42,7 @@ public:
41 float start_time; 42 float start_time;
42 float end_time; 43 float end_time;
43 string name; 44 string name;
  45 + int rotate;
44 46
45 float duration; 47 float duration;
46 int index; 48 int index;
@@ -133,6 +135,7 @@ void addinfo(string t, string name, bool bstart){ @@ -133,6 +135,7 @@ void addinfo(string t, string name, bool bstart){
133 f.end_time = f.start_time; 135 f.end_time = f.start_time;
134 f.name = name; 136 f.name = name;
135 f.m_type = mtype; 137 f.m_type = mtype;
  138 + f.rotate = 0;
136 139
137 if (!first_time_set) { 140 if (!first_time_set) {
138 first_time_set = true; 141 first_time_set = true;
@@ -160,6 +163,21 @@ void addinfo(string t, string name, bool bstart){ @@ -160,6 +163,21 @@ void addinfo(string t, string name, bool bstart){
160 } 163 }
161 } 164 }
162 165
  166 +void addinfo(const char * t, const char * name, const char * rotation){
  167 + int i = 0;
  168 + for (; i < media_files.size(); i++) {
  169 + if (media_files[i].name == name) {
  170 + media_files[i].rotate = atoi(rotation);
  171 + break;
  172 + }
  173 + }
  174 +
  175 + if (i == media_files.size())
  176 + {
  177 + printf("\nerror ,file : %s info but not found!", name);
  178 + }
  179 +}
  180 +
163 void addinfo(float start, float duration, string name, int channel){ 181 void addinfo(float start, float duration, string name, int channel){
164 media_type mtype = mt_av; 182 media_type mtype = mt_av;
165 fileinfo f; 183 fileinfo f;
@@ -231,10 +249,25 @@ void merge_audio_pic(const char * audio, const char * picfile, const char * dest @@ -231,10 +249,25 @@ void merge_audio_pic(const char * audio, const char * picfile, const char * dest
231 } 249 }
232 250
233 251
234 -void merge_audio_video(const char * audio, const char * video, const char * destfile) 252 +void merge_audio_video(const char * audio, const char * video, int rotate, const char * destfile)
235 { 253 {
236 char buf[2048]; 254 char buf[2048];
237 - sprintf(buf, "ffmpeg -y -i %s -i %s %s %s %s", audio, video, acodec_param, vcodec_param, destfile); 255 + if (0 == rotate) {
  256 + sprintf(buf, "ffmpeg -y -i %s -i %s %s %s %s", audio, video, acodec_param, vcodec_param, destfile);
  257 + }
  258 + else {
  259 + const char * vf = "";
  260 + if (rotate == 180){
  261 + vf = "-vf rotate=PI";
  262 + }
  263 + else if (rotate == 90) {
  264 + vf = "-vf rotate=PI/2";
  265 + }
  266 + else if (rotate == 270) {
  267 + vf = "-vf rotate=PI*3/2";
  268 + }
  269 + sprintf(buf, "ffmpeg -y -i %s -i %s %s %s %s %s", audio, video, acodec_param, vf, vcodec_param, destfile);
  270 + }
238 run_shell_cmd(buf); 271 run_shell_cmd(buf);
239 } 272 }
240 273
@@ -563,6 +596,7 @@ void add_media_infos() @@ -563,6 +596,7 @@ void add_media_infos()
563 m.channel = f.channel; 596 m.channel = f.channel;
564 m.duration = f.end_time - f.start_time; 597 m.duration = f.end_time - f.start_time;
565 m.type_time = m.start_time; 598 m.type_time = m.start_time;
  599 + m.rotate = f.rotate;
566 add_media_info(m); 600 add_media_info(m);
567 m.t_type = tt_end; 601 m.t_type = tt_end;
568 m.type_time = m.end_time; 602 m.type_time = m.end_time;
@@ -666,7 +700,7 @@ int merge_audio_video(vector<media_info> & files) @@ -666,7 +700,7 @@ int merge_audio_video(vector<media_info> & files)
666 700
667 701
668 sprintf(destfile, "%d.ts", nf); 702 sprintf(destfile, "%d.ts", nf);
669 - merge_audio_video(audio_file, video.name.c_str(), destfile); 703 + merge_audio_video(audio_file, video.name.c_str(), video.rotate, destfile);
670 merged_files.push_back(destfile); 704 merged_files.push_back(destfile);
671 nf++; 705 nf++;
672 706
@@ -1369,6 +1403,14 @@ int readfile(char * filename) @@ -1369,6 +1403,14 @@ int readfile(char * filename)
1369 else if (res[2] == "close") { 1403 else if (res[2] == "close") {
1370 addinfo(res[0], res[1], false); 1404 addinfo(res[0], res[1], false);
1371 } 1405 }
  1406 + else if (res[2] == "info") {
  1407 + if (res.size() > 5) {
  1408 + const char * pInfo = res[5].c_str();
  1409 + if (!strncmp(pInfo, "rotation=", 9)){
  1410 + addinfo(res[0].c_str(), res[1].c_str(), pInfo + 9);
  1411 + }
  1412 + }
  1413 + }
1372 } 1414 }
1373 } 1415 }
1374 return 0; 1416 return 0;