From bb5f8e269a7d0b3de3406cb23d74bc418db6b57c Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sun, 4 Oct 2020 13:47:56 +0200 Subject: [PATCH] splitvideo: ffprobe to find duration. --- splitvideo/splitvideo | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/splitvideo/splitvideo b/splitvideo/splitvideo index 9ddda49..6e21ae6 100755 --- a/splitvideo/splitvideo +++ b/splitvideo/splitvideo @@ -135,16 +135,12 @@ sub videolength { # Return: # length of $file in 00:00:00.0 format my $file = shell_quote_scalar_default(shift); - # mp4info 'The future of London'"'"'s airports-KXmpdJO9UOc.mp4' - # The future of London's airports-KXmpdJO9UOc.mp4: - # Track Type Info - # 1 video H264 Main@3.1, 561.560 secs, 932 kbps, 1280x720 @ 25.000000 fps - # 2 audio MPEG-4 AAC LC, 561.574 secs, 0 kbps, 44100 Hz - open(my $fh, "-|", "mp4info $file") || die; + # ffprobe 'The future of London'"'"'s airports-KXmpdJO9UOc.mp4' + # Duration: 00:25:36.92, start: 0.000000, bitrate: 441 kb/s + open(my $fh, "-|", "ffprobe $file 2>&1") || die; my $length = 0; for(<$fh>) { - /(\d+.\d+) secs/ and $length = max($1,$length); - warn $_; + /Duration: (\d\d:\d\d:\d\d.\d+)/ and $length = max($1,$length); } $length ||= "99:99:99.9"; $length = format_time($length); @@ -159,7 +155,7 @@ sub max(@) { # Skip undefs defined $_ or next; defined $max or do { $max = $_; next; }; # Set $_ to the first non-undef - $max = ($max > $_) ? $max : $_; + $max = ($max gt $_) ? $max : $_; } return $max; }