[FFmpeg-user] Forcing ffmpeg to detect duration reliably

tracey jaquith tracey at archive.org
Fri Mar 1 16:25:05 CET 2013


On Mar 1, 2013, at 2:47 AM, Robert Krüger <krueger at lesspain.de> wrote:

> On Fri, Mar 1, 2013 at 10:51 AM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
>> Robert Krüger <krueger <at> lesspain.de> writes:
>> 
>>> I assumed that if I make probesize large enough
>>> (larger than the entire file in my case, which is a
>>> bit over 4 MB) that ffmpeg would be able to detect
>>> the accurate duration
>> 
>> Just in case this is not clear:
>> -analyzeduration has nothing to do with analyzing the
>> duration of the input file, it means the duration (ms)
>> used to analyze the sample.
> yes, I saw stefano's commit with the respective documentation change
> and should have left it out of the command line.
> 
>> 
>> You can use "ffmpeg -i input -f null -" to determine
>> the actual duration of input.
>> (In your sample case, the input video is vbr, meaning
>> there is no way of knowing the duration without
>> going through the whole file as in decoding. You can
>> speed up this operation but you have to invoke the
>> decoder.)
> OK, thank you for that information. Just to be sure, by decoding you
> mean bitstream parsing as in av_parser_parse2 (see other thread on
> libav-user) , not necessarily decoding any picture data, right?
> 
> Regards,
> 
> Robert


In case helpful,
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());'
1800

(on my fairly beefy linux server, runtime of 3 seconds versus 60 seconds, for a 30 minute MPEG-TS)

--tracey
TV Archive / archive.org


More information about the ffmpeg-user mailing list