for mp4 file, convert to ts,and then to mkv to get the correct duration
正在显示
2 个修改的文件
包含
96 行增加
和
2 行删除
| @@ -299,9 +299,56 @@ float parse_ffmpeg_duration(const char * file) | @@ -299,9 +299,56 @@ float parse_ffmpeg_duration(const char * file) | ||
| 299 | return hour * 3600 + minute * 60 + sec; | 299 | return hour * 3600 + minute * 60 + sec; |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | +float get_mp4_duration(const char *mediafile, bool bVideo) | ||
| 303 | +{ | ||
| 304 | + char buf[2048]; | ||
| 305 | + | ||
| 306 | + if (bVideo){ | ||
| 307 | + sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.ts", mediafile, mediafile); | ||
| 308 | + } | ||
| 309 | + else { | ||
| 310 | + sprintf(buf, "ffmpeg -y -i %s -acodec copy -vn %s.ts", mediafile, mediafile); | ||
| 311 | + } | ||
| 312 | + run_shell_cmd(buf); | ||
| 313 | + | ||
| 314 | + if (bVideo){ | ||
| 315 | + sprintf(buf, "ffmpeg -y -i %s.ts -vcodec copy -an %s.mkv", mediafile, mediafile); | ||
| 316 | + } | ||
| 317 | + else { | ||
| 318 | + sprintf(buf, "ffmpeg -y -i %s.ts -acodec copy -vn %s.mkv", mediafile, mediafile); | ||
| 319 | + } | ||
| 320 | + run_shell_cmd(buf); | ||
| 321 | + | ||
| 322 | +#ifdef WIN32 | ||
| 323 | + sprintf(buf, "ffmpeg -i %s.mkv > %s.txt 2>&1", mediafile, mediafile); | ||
| 324 | +#else | ||
| 325 | + sprintf(buf, "ffmpeg -i %s.mkv &> %s.txt", mediafile, mediafile); | ||
| 326 | +#endif | ||
| 327 | + | ||
| 328 | + run_shell_cmd(buf); | ||
| 329 | + | ||
| 330 | + if (!keep_tmp_files) { | ||
| 331 | + char buf[2048]; | ||
| 332 | + sprintf(buf, "%s.ts", mediafile); | ||
| 333 | + remove_file(buf); | ||
| 334 | + sprintf(buf, "%s.mkv", mediafile); | ||
| 335 | + remove_file(buf); | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | + | ||
| 339 | + sprintf(buf, "%s.txt", mediafile); | ||
| 340 | + return parse_ffmpeg_duration(buf); | ||
| 341 | +} | ||
| 342 | + | ||
| 302 | float get_file_duration(const char *mediafile, bool bVideo) | 343 | float get_file_duration(const char *mediafile, bool bVideo) |
| 303 | { | 344 | { |
| 304 | char buf[2048]; | 345 | char buf[2048]; |
| 346 | + int len = strlen(mediafile); | ||
| 347 | + if (len > 3) { | ||
| 348 | + if (!_stricmp(mediafile + len - 4, ".mp4")) { | ||
| 349 | + return get_mp4_duration(mediafile, bVideo); | ||
| 350 | + } | ||
| 351 | + } | ||
| 305 | if (bVideo){ | 352 | if (bVideo){ |
| 306 | sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.mkv", mediafile, mediafile); | 353 | sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.mkv", mediafile, mediafile); |
| 307 | } | 354 | } |
| @@ -1007,7 +1054,7 @@ void get_outinfo_file_name(char * input) | @@ -1007,7 +1054,7 @@ void get_outinfo_file_name(char * input) | ||
| 1007 | int main(int argc, char * argv[]) | 1054 | int main(int argc, char * argv[]) |
| 1008 | { | 1055 | { |
| 1009 | if (argc < 2) { | 1056 | if (argc < 2) { |
| 1010 | - printf(" merge_av 1.0.8\n"); | 1057 | + printf(" merge_av 1.0.9\n"); |
| 1011 | printf(" run ffmpeg to merge audio and video files according to the record info file,\nusage:"); | 1058 | printf(" run ffmpeg to merge audio and video files according to the record info file,\nusage:"); |
| 1012 | printf("\n %s record_info_filename [-p] [-k]", argv[0]); | 1059 | printf("\n %s record_info_filename [-p] [-k]", argv[0]); |
| 1013 | printf("\n -p :only print the command,don't run ffmpeg"); | 1060 | printf("\n -p :only print the command,don't run ffmpeg"); |
| @@ -343,9 +343,56 @@ float parse_ffmpeg_duration(const char * file) | @@ -343,9 +343,56 @@ float parse_ffmpeg_duration(const char * file) | ||
| 343 | return hour * 3600 + minute * 60 + sec; | 343 | return hour * 3600 + minute * 60 + sec; |
| 344 | } | 344 | } |
| 345 | 345 | ||
| 346 | +float get_mp4_duration(const char *mediafile, bool bVideo) | ||
| 347 | +{ | ||
| 348 | + char buf[2048]; | ||
| 349 | + | ||
| 350 | + if (bVideo){ | ||
| 351 | + sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.ts", mediafile, mediafile); | ||
| 352 | + } | ||
| 353 | + else { | ||
| 354 | + sprintf(buf, "ffmpeg -y -i %s -acodec copy -vn %s.ts", mediafile, mediafile); | ||
| 355 | + } | ||
| 356 | + run_shell_cmd(buf); | ||
| 357 | + | ||
| 358 | + if (bVideo){ | ||
| 359 | + sprintf(buf, "ffmpeg -y -i %s.ts -vcodec copy -an %s.mkv", mediafile, mediafile); | ||
| 360 | +} | ||
| 361 | + else { | ||
| 362 | + sprintf(buf, "ffmpeg -y -i %s.ts -acodec copy -vn %s.mkv", mediafile, mediafile); | ||
| 363 | + } | ||
| 364 | + run_shell_cmd(buf); | ||
| 365 | + | ||
| 366 | +#ifdef WIN32 | ||
| 367 | + sprintf(buf, "ffmpeg -i %s.mkv > %s.txt 2>&1", mediafile, mediafile); | ||
| 368 | +#else | ||
| 369 | + sprintf(buf, "ffmpeg -i %s.mkv &> %s.txt", mediafile, mediafile); | ||
| 370 | +#endif | ||
| 371 | + | ||
| 372 | + run_shell_cmd(buf); | ||
| 373 | + | ||
| 374 | + if (!keep_tmp_files) { | ||
| 375 | + char buf[2048]; | ||
| 376 | + sprintf(buf, "%s.ts", mediafile); | ||
| 377 | + remove_file(buf); | ||
| 378 | + sprintf(buf, "%s.mkv", mediafile); | ||
| 379 | + remove_file(buf); | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + | ||
| 383 | + sprintf(buf, "%s.txt", mediafile); | ||
| 384 | + return parse_ffmpeg_duration(buf); | ||
| 385 | +} | ||
| 386 | + | ||
| 346 | float get_file_duration(const char *mediafile, bool bVideo) | 387 | float get_file_duration(const char *mediafile, bool bVideo) |
| 347 | { | 388 | { |
| 348 | char buf[2048]; | 389 | char buf[2048]; |
| 390 | + int len = strlen(mediafile); | ||
| 391 | + if (len > 3) { | ||
| 392 | + if (!_stricmp(mediafile + len - 4, ".mp4")) { | ||
| 393 | + return get_mp4_duration(mediafile, bVideo); | ||
| 394 | + } | ||
| 395 | + } | ||
| 349 | if (bVideo){ | 396 | if (bVideo){ |
| 350 | sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.mkv", mediafile, mediafile); | 397 | sprintf(buf, "ffmpeg -y -i %s -vcodec copy -an %s.mkv", mediafile, mediafile); |
| 351 | } | 398 | } |
| @@ -1440,7 +1487,7 @@ void get_outinfo_file_name(char * input) | @@ -1440,7 +1487,7 @@ void get_outinfo_file_name(char * input) | ||
| 1440 | int main(int argc, char * argv[]) | 1487 | int main(int argc, char * argv[]) |
| 1441 | { | 1488 | { |
| 1442 | if (argc < 3) { | 1489 | if (argc < 3) { |
| 1443 | - printf(" merge_pip 1.0.0\n"); | 1490 | + printf(" merge_pip 1.0.1\n"); |
| 1444 | printf(" run ffmpeg to merge video files to one pip video according to record info file,\nusage:"); | 1491 | printf(" run ffmpeg to merge video files to one pip video according to record info file,\nusage:"); |
| 1445 | printf("\n %s record_info_filename1 record_filename2 [-p] [-k]", argv[0]); | 1492 | printf("\n %s record_info_filename1 record_filename2 [-p] [-k]", argv[0]); |
| 1446 | printf("\n -p :only print the command,don't run ffmpeg"); | 1493 | printf("\n -p :only print the command,don't run ffmpeg"); |
-
请 注册 或 登录 后发表评论