胡斌

for mp4 file, convert to ts,and then to mkv to get the correct duration

... ... @@ -299,9 +299,56 @@ float parse_ffmpeg_duration(const char * file)
return hour * 3600 + minute * 60 + sec;
}
float get_mp4_duration(const char *mediafile, bool bVideo)
{
char buf[2048];
if (bVideo){
sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.ts", mediafile, mediafile);
}
else {
sprintf(buf, "ffmpeg -y -i %s -acodec copy -vn %s.ts", mediafile, mediafile);
}
run_shell_cmd(buf);
if (bVideo){
sprintf(buf, "ffmpeg -y -i %s.ts -vcodec copy -an %s.mkv", mediafile, mediafile);
}
else {
sprintf(buf, "ffmpeg -y -i %s.ts -acodec copy -vn %s.mkv", mediafile, mediafile);
}
run_shell_cmd(buf);
#ifdef WIN32
sprintf(buf, "ffmpeg -i %s.mkv > %s.txt 2>&1", mediafile, mediafile);
#else
sprintf(buf, "ffmpeg -i %s.mkv &> %s.txt", mediafile, mediafile);
#endif
run_shell_cmd(buf);
if (!keep_tmp_files) {
char buf[2048];
sprintf(buf, "%s.ts", mediafile);
remove_file(buf);
sprintf(buf, "%s.mkv", mediafile);
remove_file(buf);
}
sprintf(buf, "%s.txt", mediafile);
return parse_ffmpeg_duration(buf);
}
float get_file_duration(const char *mediafile, bool bVideo)
{
char buf[2048];
int len = strlen(mediafile);
if (len > 3) {
if (!_stricmp(mediafile + len - 4, ".mp4")) {
return get_mp4_duration(mediafile, bVideo);
}
}
if (bVideo){
sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.mkv", mediafile, mediafile);
}
... ... @@ -1007,7 +1054,7 @@ void get_outinfo_file_name(char * input)
int main(int argc, char * argv[])
{
if (argc < 2) {
printf(" merge_av 1.0.8\n");
printf(" merge_av 1.0.9\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");
... ...
... ... @@ -343,9 +343,56 @@ float parse_ffmpeg_duration(const char * file)
return hour * 3600 + minute * 60 + sec;
}
float get_mp4_duration(const char *mediafile, bool bVideo)
{
char buf[2048];
if (bVideo){
sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.ts", mediafile, mediafile);
}
else {
sprintf(buf, "ffmpeg -y -i %s -acodec copy -vn %s.ts", mediafile, mediafile);
}
run_shell_cmd(buf);
if (bVideo){
sprintf(buf, "ffmpeg -y -i %s.ts -vcodec copy -an %s.mkv", mediafile, mediafile);
}
else {
sprintf(buf, "ffmpeg -y -i %s.ts -acodec copy -vn %s.mkv", mediafile, mediafile);
}
run_shell_cmd(buf);
#ifdef WIN32
sprintf(buf, "ffmpeg -i %s.mkv > %s.txt 2>&1", mediafile, mediafile);
#else
sprintf(buf, "ffmpeg -i %s.mkv &> %s.txt", mediafile, mediafile);
#endif
run_shell_cmd(buf);
if (!keep_tmp_files) {
char buf[2048];
sprintf(buf, "%s.ts", mediafile);
remove_file(buf);
sprintf(buf, "%s.mkv", mediafile);
remove_file(buf);
}
sprintf(buf, "%s.txt", mediafile);
return parse_ffmpeg_duration(buf);
}
float get_file_duration(const char *mediafile, bool bVideo)
{
char buf[2048];
int len = strlen(mediafile);
if (len > 3) {
if (!_stricmp(mediafile + len - 4, ".mp4")) {
return get_mp4_duration(mediafile, bVideo);
}
}
if (bVideo){
sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.mkv", mediafile, mediafile);
}
... ... @@ -1440,7 +1487,7 @@ void get_outinfo_file_name(char * input)
int main(int argc, char * argv[])
{
if (argc < 3) {
printf(" merge_pip 1.0.0\n");
printf(" merge_pip 1.0.1\n");
printf(" run ffmpeg to merge video files to one pip video according to record info file,\nusage:");
printf("\n %s record_info_filename1 record_filename2 [-p] [-k]", argv[0]);
printf("\n -p :only print the command,don't run ffmpeg");
... ...