胡斌

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

set the version to 1.1.0
... ... @@ -11,6 +11,7 @@
bool only_print = false;
bool keep_tmp_files = false;
bool only_convert_mp4 = false;
using namespace std;
enum media_type{
... ... @@ -184,6 +185,13 @@ void merge_audio_video(const char * audio, const char * video, const char * dest
run_shell_cmd(buf);
}
void convert_video_to_ts(const char * video, const char * destfile)
{
char buf[2048];
sprintf(buf, "ffmpeg -y -i %s %s %s %s",video, acodec_param, vcodec_param, destfile);
run_shell_cmd(buf);
}
void merge_video_silence(fileinfo video, const char * aacfile, const char * destfile)
{
char buf[2048];
... ... @@ -504,8 +512,10 @@ void init()
strcpy(silence_aac_file, cfg_path);
strcat(silence_aac_file, "silence.aac");
check_audio_duration();
get_duration_from_video_file();
if (only_convert_mp4 == false) {
check_audio_duration();
get_duration_from_video_file();
}
add_media_infos();
nv = 0;
... ... @@ -973,7 +983,7 @@ int process_files()
for (int i = 0; i < media_files.size(); i++){
fileinfo video = media_files[i];
get_output_file_name(i, video.name.c_str(), outputfile);
merge_video_silence(video, silence_aac_file, destfile);
merge_video_silence(video, silence_aac_file, outputfile);
save_out_info(video.start_time, outputfile);
}
}
... ... @@ -989,6 +999,37 @@ int process_files()
return 0;
}
int process_only_mp4_files()
{
//only convert mp4 to ts,don't merge
printf("\only convert mp4 files!\n");
char outputfile[1024];
init();
if (!media_files.size()){
return 0;
}
fp_out_info = fopen(out_info_file, "wt");
for (int i = 0; i < media_files.size(); i++){
fileinfo video = media_files[i];
if (video.m_type == mt_audio) {
continue;
}
get_output_file_name(i, video.name.c_str(), outputfile);
convert_video_to_ts(video.name.c_str(), outputfile);
save_out_info(video.start_time, outputfile);
}
if (fp_out_info) {
fclose(fp_out_info);
}
return 0;
}
int readfile(char * filename)
{
ifstream fin(filename);
... ... @@ -1058,11 +1099,12 @@ void get_outinfo_file_name(char * input)
int main(int argc, char * argv[])
{
if (argc < 2) {
printf(" merge_av 1.0.9\n");
printf(" merge_av 1.1.0\n");
printf(" run ffmpeg to merge audio and video files according to the record info file,\nusage:");
printf("\n %s record_info_filename [-p] [-k]", argv[0]);
printf("\n -p :only print the command,don't run ffmpeg");
printf("\n -k :keep the temp files\n");
printf("\n -c :only convert mp4 files\n");
return -1;
}
... ... @@ -1078,6 +1120,9 @@ int main(int argc, char * argv[])
else if (!strcmp(argv[i], "-k")){
keep_tmp_files = true;
}
else if (!strcmp(argv[i], "-c")){
only_convert_mp4 = true;
}
}
get_outinfo_file_name(argv[1]);
... ... @@ -1086,7 +1131,12 @@ int main(int argc, char * argv[])
load_codec_param();
process_files();
if (only_convert_mp4 == true) {
process_only_mp4_files();
}
else {
process_files();
}
return 0;
}
... ...