胡斌

add command parameter "-c",to support only convert mp4 to ts

set the version to 1.1.0
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 11
12 bool only_print = false; 12 bool only_print = false;
13 bool keep_tmp_files = false; 13 bool keep_tmp_files = false;
  14 +bool only_convert_mp4 = false;
14 using namespace std; 15 using namespace std;
15 16
16 enum media_type{ 17 enum media_type{
@@ -184,6 +185,13 @@ void merge_audio_video(const char * audio, const char * video, const char * dest @@ -184,6 +185,13 @@ void merge_audio_video(const char * audio, const char * video, const char * dest
184 run_shell_cmd(buf); 185 run_shell_cmd(buf);
185 } 186 }
186 187
  188 +void convert_video_to_ts(const char * video, const char * destfile)
  189 +{
  190 + char buf[2048];
  191 + sprintf(buf, "ffmpeg -y -i %s %s %s %s",video, acodec_param, vcodec_param, destfile);
  192 + run_shell_cmd(buf);
  193 +}
  194 +
187 void merge_video_silence(fileinfo video, const char * aacfile, const char * destfile) 195 void merge_video_silence(fileinfo video, const char * aacfile, const char * destfile)
188 { 196 {
189 char buf[2048]; 197 char buf[2048];
@@ -504,8 +512,10 @@ void init() @@ -504,8 +512,10 @@ void init()
504 strcpy(silence_aac_file, cfg_path); 512 strcpy(silence_aac_file, cfg_path);
505 strcat(silence_aac_file, "silence.aac"); 513 strcat(silence_aac_file, "silence.aac");
506 514
507 - check_audio_duration();  
508 - get_duration_from_video_file(); 515 + if (only_convert_mp4 == false) {
  516 + check_audio_duration();
  517 + get_duration_from_video_file();
  518 + }
509 add_media_infos(); 519 add_media_infos();
510 520
511 nv = 0; 521 nv = 0;
@@ -973,7 +983,7 @@ int process_files() @@ -973,7 +983,7 @@ int process_files()
973 for (int i = 0; i < media_files.size(); i++){ 983 for (int i = 0; i < media_files.size(); i++){
974 fileinfo video = media_files[i]; 984 fileinfo video = media_files[i];
975 get_output_file_name(i, video.name.c_str(), outputfile); 985 get_output_file_name(i, video.name.c_str(), outputfile);
976 - merge_video_silence(video, silence_aac_file, destfile); 986 + merge_video_silence(video, silence_aac_file, outputfile);
977 save_out_info(video.start_time, outputfile); 987 save_out_info(video.start_time, outputfile);
978 } 988 }
979 } 989 }
@@ -989,6 +999,37 @@ int process_files() @@ -989,6 +999,37 @@ int process_files()
989 return 0; 999 return 0;
990 } 1000 }
991 1001
  1002 +int process_only_mp4_files()
  1003 +{
  1004 + //only convert mp4 to ts,don't merge
  1005 + printf("\only convert mp4 files!\n");
  1006 + char outputfile[1024];
  1007 + init();
  1008 +
  1009 + if (!media_files.size()){
  1010 + return 0;
  1011 + }
  1012 +
  1013 + fp_out_info = fopen(out_info_file, "wt");
  1014 +
  1015 + for (int i = 0; i < media_files.size(); i++){
  1016 + fileinfo video = media_files[i];
  1017 + if (video.m_type == mt_audio) {
  1018 + continue;
  1019 + }
  1020 + get_output_file_name(i, video.name.c_str(), outputfile);
  1021 + convert_video_to_ts(video.name.c_str(), outputfile);
  1022 + save_out_info(video.start_time, outputfile);
  1023 + }
  1024 +
  1025 + if (fp_out_info) {
  1026 + fclose(fp_out_info);
  1027 + }
  1028 +
  1029 + return 0;
  1030 +
  1031 +}
  1032 +
992 int readfile(char * filename) 1033 int readfile(char * filename)
993 { 1034 {
994 ifstream fin(filename); 1035 ifstream fin(filename);
@@ -1058,11 +1099,12 @@ void get_outinfo_file_name(char * input) @@ -1058,11 +1099,12 @@ void get_outinfo_file_name(char * input)
1058 int main(int argc, char * argv[]) 1099 int main(int argc, char * argv[])
1059 { 1100 {
1060 if (argc < 2) { 1101 if (argc < 2) {
1061 - printf(" merge_av 1.0.9\n"); 1102 + printf(" merge_av 1.1.0\n");
1062 printf(" run ffmpeg to merge audio and video files according to the record info file,\nusage:"); 1103 printf(" run ffmpeg to merge audio and video files according to the record info file,\nusage:");
1063 printf("\n %s record_info_filename [-p] [-k]", argv[0]); 1104 printf("\n %s record_info_filename [-p] [-k]", argv[0]);
1064 printf("\n -p :only print the command,don't run ffmpeg"); 1105 printf("\n -p :only print the command,don't run ffmpeg");
1065 printf("\n -k :keep the temp files\n"); 1106 printf("\n -k :keep the temp files\n");
  1107 + printf("\n -c :only convert mp4 files\n");
1066 return -1; 1108 return -1;
1067 } 1109 }
1068 1110
@@ -1078,6 +1120,9 @@ int main(int argc, char * argv[]) @@ -1078,6 +1120,9 @@ int main(int argc, char * argv[])
1078 else if (!strcmp(argv[i], "-k")){ 1120 else if (!strcmp(argv[i], "-k")){
1079 keep_tmp_files = true; 1121 keep_tmp_files = true;
1080 } 1122 }
  1123 + else if (!strcmp(argv[i], "-c")){
  1124 + only_convert_mp4 = true;
  1125 + }
1081 } 1126 }
1082 1127
1083 get_outinfo_file_name(argv[1]); 1128 get_outinfo_file_name(argv[1]);
@@ -1086,7 +1131,12 @@ int main(int argc, char * argv[]) @@ -1086,7 +1131,12 @@ int main(int argc, char * argv[])
1086 1131
1087 load_codec_param(); 1132 load_codec_param();
1088 1133
1089 - process_files(); 1134 + if (only_convert_mp4 == true) {
  1135 + process_only_mp4_files();
  1136 + }
  1137 + else {
  1138 + process_files();
  1139 + }
1090 1140
1091 return 0; 1141 return 0;
1092 } 1142 }