splitvideo: ffprobe to find duration.

This commit is contained in:
Ole Tange 2020-10-04 13:47:56 +02:00
parent a25a6e044e
commit bb5f8e269a

View file

@ -135,16 +135,12 @@ sub videolength {
# Return: # Return:
# length of $file in 00:00:00.0 format # length of $file in 00:00:00.0 format
my $file = shell_quote_scalar_default(shift); my $file = shell_quote_scalar_default(shift);
# mp4info 'The future of London'"'"'s airports-KXmpdJO9UOc.mp4' # ffprobe 'The future of London'"'"'s airports-KXmpdJO9UOc.mp4'
# The future of London's airports-KXmpdJO9UOc.mp4: # Duration: 00:25:36.92, start: 0.000000, bitrate: 441 kb/s
# Track Type Info open(my $fh, "-|", "ffprobe $file 2>&1") || die;
# 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;
my $length = 0; my $length = 0;
for(<$fh>) { for(<$fh>) {
/(\d+.\d+) secs/ and $length = max($1,$length); /Duration: (\d\d:\d\d:\d\d.\d+)/ and $length = max($1,$length);
warn $_;
} }
$length ||= "99:99:99.9"; $length ||= "99:99:99.9";
$length = format_time($length); $length = format_time($length);
@ -159,7 +155,7 @@ sub max(@) {
# Skip undefs # Skip undefs
defined $_ or next; defined $_ or next;
defined $max or do { $max = $_; next; }; # Set $_ to the first non-undef defined $max or do { $max = $_; next; }; # Set $_ to the first non-undef
$max = ($max > $_) ? $max : $_; $max = ($max gt $_) ? $max : $_;
} }
return $max; return $max;
} }