[FFmpeg-user] How to get he total number of frames

Peter White peter.white at posteo.net
Tue Mar 9 14:37:23 EET 2021

On Tue, Mar 09, 2021 at 01:07:41PM +0100, Nicolas George wrote:
> Peter White (12021-03-09):
> > Would you mind answering the OP's question with a command line example,
> > then?
> I help people who help themselves, thus avoiding Russel's paradox.

Sorry, I don't know that one and cannot grasp it at the moment, but I
guess it is similar to teaching a starving man how to fish instead of
just giving him one fish? I haven't seen much teaching yet, though. Not
even a pointer other than: ffprobe can do that.

> > I am well aware of that, but nobody said anything about parsing.
> Oh? Please, explain to me how you extract the number of frames from the
> statistics line without parsing it?

By reading the line, which technically is parsing as well, but I am more
flexible than any stupid script.

> > ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 input.mkv
> Do not use "-v error" if you want help.

Sorry, why would it matter what other output comes from above command?
> > No need for output because it takes to long to complete: roughly one
> > minute for a 20 minute video as opposed to virtually no time with:
> > 
> > ffmpeg -i input.mkv -an -sn -c copy -f null -
> -c copy tells ffmpeg to dispense with the decoder, which means it does
> not count frames but packets.

Is there a meaningful difference in this context? I did have a similar
solution in a script, using PyAV, which counted packets instead of
frames, because it is faster.

> Have you tried telling ffprobe to count packets?

Now we are getting somewhere. No, I have not, because I did not know it
can do that. But above question remains: does packet count always equal
frame count? What might be pitfalls with this approach?


More information about the ffmpeg-user mailing list