[FFmpeg-user] Forcing ffmpeg to detect duration reliably
S. Fisher
expandafter at yahoo.com
Tue Jul 16 02:16:15 CEST 2013
tracey jaquith <tracey <at> archive.org> wrote:
> I use this for our archives when I get an estimated duration
> that seems wrong. Much faster than the "ffmpeg -i input -f null
> -", though I'm sure there may be some pros/cons.
>
> It uses "ffprobe" to "count video packets" and their durations,
> finally printing a total #seconds.
>
>
> ffprobe -select_streams v -show_packets -print_format compact *mpg 2>/dev/null | egrep -o 'duration_time=[^ ]+'|cut -f2 -d= | perl -ne 'chop; $n+=$_; print (int($n*10)/10)."\n" if (eof());'
Instead of using egrep, cut, and perl, it seems somewhat simpler
to use the small language awk.
ffprobe -select_streams v -show_packets -print_format compact foo.mp4 | mawk -F "duration_time=" "NF>1 {t+=$2} END{printf '%.1f', t}"
Tested in a DOS shell under windoze.
More information about the ffmpeg-user
mailing list