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

Peter White peter.white at posteo.net
Fri Mar 12 11:10:03 EET 2021


On Fri, Mar 12, 2021 at 02:11:14AM -0500, Mark Filipak (ffmpeg) wrote:
> On 2021-03-11 18:37, Reino Wijnsma wrote:
> > On 2021-03-09T20:43:21+0100, Mark Filipak (ffmpeg) <markfilipak at bog.us> wrote:
> > > On 2021-03-09 03:58, Michael Koch wrote:
> > > > These links might help:
> > > > https://stackoverflow.com/questions/2017843/fetch-frame-count-with-ffmpeg
> > > > https://superuser.com/questions/1512575/why-total-frame-count-is-different-in-ffmpeg-than-ffprobe
> > > > 
> > > > Michael
> > > 
> > > Those links are really hard to follow and it's fruitless to try to find what's there that works vs. what doesn't work.
> > > 
> > >  From Ulf Zibis:
> > > can one please tell me, how I can get the total number of frames of a video?
> > > 
> > > Was Ulf's question actually answered? I think not.
> > 
> > How can you say that? These urls do exactly that. They offer a couple of solutions on how to get the total number of frames.
> > What is so hard to follow?
> 
> 
> Re, https://stackoverflow.com/questions/2017843/fetch-frame-count-with-ffmpeg.
> I think this:
> 'ffmpeg -i input.mkv -map 0:v:0 -c copy -f null -'

As was established in this discussion, ffmpeg is simply not the right
tool for that. I, who suggested using it, know better now. Thanks BTW to
Nicolas.

> [1] Specifically, videos copied from DVDs with 'drawtext...text=%{n}' but
> that show burned-in frame number beginning with '1' (or '2' or '3' ..).
> Example:
> Frame #s 1..3596 <=burned-in
> @ 30/1.001fps <=confirmed
> with 2:00.071 running time <= 3598.[516483..] to 3598.[5464..] actual frames

Obviously, there cannot be fractions of frames, hence you always need to
round up.

> "frame= 3596 fps= 30 q=15.8 Lsize=   87555kB time=00:02:00.03
> bitrate=5975.2kbits/s dup=0 drop=1 speed=0.988x" <= last line of log
> -- What is a person to believe?

And that is exactly what happened here. But to reiterate what Nicolas
pointed out, the copy codec effectively disables decoding and hence
counts *packets* not frames.

Anyway, ffmpeg is not the right tool, as I myself have learned in this
very thread. ffprobe -count_frames should be used. Yes it is rather slow
but that is because a packet needs to be decoded first to get the frame.


More information about the ffmpeg-user mailing list