胡斌

first version

正在显示 1 个修改的文件 包含 50 行增加24 行删除
@@ -102,7 +102,7 @@ void get_config_path(){ @@ -102,7 +102,7 @@ void get_config_path(){
102 const char * default_vcodec_param = "-vcodec libx264 -level 3.1 -preset veryfast -g 100 -r 20 -bf 0 -vsync cfr"; 102 const char * default_vcodec_param = "-vcodec libx264 -level 3.1 -preset veryfast -g 100 -r 20 -bf 0 -vsync cfr";
103 const char * default_acodec_param = "-acodec copy"; 103 const char * default_acodec_param = "-acodec copy";
104 const char * default_av_codec_param = "-acodec aac -vcodec libx264 -level 3.1 -preset veryfast -g 100 -r 20 -bf 0 -vsync cfr"; 104 const char * default_av_codec_param = "-acodec aac -vcodec libx264 -level 3.1 -preset veryfast -g 100 -r 20 -bf 0 -vsync cfr";
105 -const char * default_pip_param = "-filter_complex \"[1:v]scale = w = 80:h = 60 : force_original_aspect_ratio = decrease[b]; [0:v][b]overlay = x = 0:y = 0\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2,volume=1"; 105 +const char * default_pip_param = "-filter_complex \"[1:v]scale=w=80:h=60:force_original_aspect_ratio=decrease[b];[0:v][b]overlay=x=0:y=0\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2,volume=1";
106 106
107 107
108 char av_codec_param[1024]; 108 char av_codec_param[1024];
@@ -408,6 +408,23 @@ int merge_audio_file(vector<string> & files, const char * dest) @@ -408,6 +408,23 @@ int merge_audio_file(vector<string> & files, const char * dest)
408 return 0; 408 return 0;
409 } 409 }
410 410
  411 +int merge_av_file(vector<string> & files, const char * dest)
  412 +{
  413 + char tsfile[1024];
  414 + vector<string> tsfiles;
  415 +
  416 + sprintf(tsfile, "m_%s.ts", dest);
  417 + concate_files(files, tsfile);
  418 +
  419 + adjust_dest_timecode(tsfile, dest);
  420 +
  421 + if (!keep_tmp_files){
  422 + tsfiles.push_back(tsfile);
  423 + removefiles(tsfiles);
  424 + }
  425 + return 0;
  426 +}
  427 +
411 428
412 list <media_info> sorted_media; 429 list <media_info> sorted_media;
413 deque<media_info> sorted_infos; 430 deque<media_info> sorted_infos;
@@ -552,6 +569,7 @@ int merge_audio_video(vector<media_info> & files) @@ -552,6 +569,7 @@ int merge_audio_video(vector<media_info> & files)
552 569
553 int merge_video_pip(vector<media_info> & files) 570 int merge_video_pip(vector<media_info> & files)
554 { 571 {
  572 + char video_file[1024];
555 vector<string> merge_video_files; 573 vector<string> merge_video_files;
556 int nsilence = 0; 574 int nsilence = 0;
557 575
@@ -559,45 +577,52 @@ int merge_video_pip(vector<media_info> & files) @@ -559,45 +577,52 @@ int merge_video_pip(vector<media_info> & files)
559 float start_time = video.start_time; 577 float start_time = video.start_time;
560 578
561 for (int i = 1; i < files.size() - 1; i += 2){ 579 for (int i = 1; i < files.size() - 1; i += 2){
562 - media_info audio = files[i];  
563 - media_info audio_end = files[i + 1];  
564 - if (audio.type_time - start_time > 0.1){ 580 + media_info video = files[i];
  581 + media_info video_end = files[i + 1];
  582 + if (video.type_time - start_time > 0.1){
565 sprintf(audio_file, "%d_%d_silence.aac", nf, nsilence++);//a duration of silence 583 sprintf(audio_file, "%d_%d_silence.aac", nf, nsilence++);//a duration of silence
566 - split_audio(silence_aac_file, 0, audio.type_time - start_time, audio_file);  
567 - merge_video_files.push_back(audio_file);  
568 - tmp_files.push_back(audio_file);  
569 - } 584 + split_audio(silence_aac_file, 0, video.type_time - start_time, audio_file);
  585 + sprintf(video_file, "%d_%d_blank.ts", nf, nsilence++);
  586 + merge_audio_pic(audio_file, blank_pic_file, video_file);
570 587
571 - if (audio.type_time - audio.start_time > 0.10 || audio_end.end_time - audio_end.type_time > 0.10) {  
572 - sprintf(audio_file, "%d_%s", nf, audio.name.c_str());  
573 - split_audio(audio.name.c_str(), audio.type_time - audio.start_time, audio_end.type_time - audio.type_time, audio_file); 588 + merge_video_files.push_back(video_file);
574 tmp_files.push_back(audio_file); 589 tmp_files.push_back(audio_file);
  590 + tmp_files.push_back(video_file);
  591 + }
575 592
  593 + if (video.type_time - video.start_time > 0.10 || video_end.end_time - video_end.type_time > 0.10) {
  594 + sprintf(video_file, "%d_%s", nf, video.name.c_str());
  595 + split_av(video.name.c_str(), video.type_time - video.start_time, video_end.type_time - video.type_time, video_file);
  596 + tmp_files.push_back(video_file);
576 } 597 }
577 else{ 598 else{
578 - strcpy(audio_file, audio.name.c_str()); 599 + strcpy(video_file, video.name.c_str());
579 } 600 }
580 601
581 - start_time = audio_end.type_time;  
582 - merge_video_files.push_back(audio_file); 602 + start_time = video_end.type_time;
  603 + merge_video_files.push_back(video_file);
583 604
584 if (i == files.size() - 2){ 605 if (i == files.size() - 2){
585 - if (video.end_time - audio_end.type_time > 0.1){ 606 + if (video.end_time - video_end.type_time > 0.1){
586 sprintf(audio_file, "%d_%d_silence.aac", nf, nsilence++);//a duration of silence 607 sprintf(audio_file, "%d_%d_silence.aac", nf, nsilence++);//a duration of silence
587 - split_audio(silence_aac_file, 0, video.end_time - audio_end.type_time, audio_file);  
588 - merge_video_files.push_back(audio_file); 608 + split_audio(silence_aac_file, 0, video.end_time - video_end.type_time, audio_file);
  609 + sprintf(video_file, "%d_%d_blank.ts", nf, nsilence++);
  610 + merge_audio_pic(audio_file, blank_pic_file, video_file);
  611 +
  612 + merge_video_files.push_back(video_file);
589 tmp_files.push_back(audio_file); 613 tmp_files.push_back(audio_file);
  614 + tmp_files.push_back(video_file);
590 } 615 }
591 } 616 }
592 } 617 }
593 618
594 - sprintf(audio_file, "%d_merged.aac", nf);  
595 - merge_audio_file(merge_video_files, audio_file);  
596 - tmp_files.push_back(audio_file); 619 + sprintf(video_file, "%d_merged.ts", nf);
  620 + merge_av_file(merge_video_files, video_file);
  621 + tmp_files.push_back(video_file);
597 622
598 623
599 sprintf(destfile, "%d.ts", nf); 624 sprintf(destfile, "%d.ts", nf);
600 - merge_audio_video(audio_file, video.name.c_str(), destfile); 625 + merge_video_pip(video_file, video.name.c_str(), destfile);
601 merged_files.push_back(destfile); 626 merged_files.push_back(destfile);
602 nf++; 627 nf++;
603 628
@@ -827,7 +852,8 @@ void get_front_info(int index_to, vector<media_info> &cur_processing) @@ -827,7 +852,8 @@ void get_front_info(int index_to, vector<media_info> &cur_processing)
827 852
828 int concate_files_and_adjust_timecode(const char * output_dest_file){ 853 int concate_files_and_adjust_timecode(const char * output_dest_file){
829 if (merged_files.size() == 1){ 854 if (merged_files.size() == 1){
830 - printf("\n rename %s to %s", merged_files[0].c_str(), output_dest_file); 855 + printf("rename %s to %s\n", merged_files[0].c_str(), output_dest_file);
  856 + remove(output_dest_file);
831 rename(merged_files[0].c_str(), output_dest_file); 857 rename(merged_files[0].c_str(), output_dest_file);
832 } 858 }
833 else { 859 else {
@@ -860,7 +886,7 @@ int get_output_file_name(int i, const char * file_prefix, char * outputfile){ @@ -860,7 +886,7 @@ int get_output_file_name(int i, const char * file_prefix, char * outputfile){
860 strcpy(prefix, file_prefix); 886 strcpy(prefix, file_prefix);
861 } 887 }
862 888
863 - sprintf(outputfile, "%s.ts", prefix, i); 889 + sprintf(outputfile, "pip_%s.ts", prefix, i);
864 return 0; 890 return 0;
865 } 891 }
866 892
@@ -918,7 +944,7 @@ int process_va_files() @@ -918,7 +944,7 @@ int process_va_files()
918 else { 944 else {
919 get_front_info(index, cur_processing); 945 get_front_info(index, cur_processing);
920 } 946 }
921 - merge_audio_video(cur_processing); 947 + merge_video_pip(cur_processing);
922 } 948 }
923 //if the duration between the processed end and the start of not processed is large than 200 ms, reopen a new file 949 //if the duration between the processed end and the start of not processed is large than 200 ms, reopen a new file
924 if (is_start){ 950 if (is_start){