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

Peter White peter.white at posteo.net
Tue Mar 9 12:48:32 EET 2021


On Tue, Mar 09, 2021 at 11:07:21AM +0100, Ulf Zibis wrote:
> 
> Am 09.03.21 um 10:43 schrieb Ulf Zibis:
> > 
> > Am 09.03.21 um 09:57 schrieb Peter White:
> > > The frame count *is* exact. The way to get there is just not that
> > > pretty. If anybody on this list knows a better one, step up, please.
> > 
> > I suspect that the last "progression" line shows the exact count, as it may only report the last progression state a few ┬Ás before the operation is completed.
> 
> Can one please clarify this?

I don't know if I understood your request correctly but here goes:

ffmpeg -i example.mkv -an -sn -c copy -f null -
...
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=31186 fps=0.0 q=-1.0 Lsize=N/A time=00:21:40.59 bitrate=N/A speed=2.67e+03x
video:162174kB audio:0kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: unknown

As you can see, in the second to last line in the first field is the
frame count. Since the copy codec gets used, I can see no reason why
this should not always show the exact total frame count of any video.

Also, note that I used a matroska file as an example, since it is one of
the mentioned special cases mentioned here:
https://stackoverflow.com/a/28376817

I had the same question you posted once and think I saw that one or a
similar answer. After some ado I came to the conclusion that the
aforementioned way is the most robust and universal one. But if I am
wrong, I would very much like to be corrected.


Peter


More information about the ffmpeg-user mailing list