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

Phil Rhodes phil_rhodes at rocketmail.com
Tue Mar 9 13:16:16 EET 2021


 I hit this once some time ago when creating an application which was intended to assign start timecodes to recorded video files and for which we needed a frame-accurate count. In that case the files were AVIs, which theoretically may have a header including a frame count, but in practice we found that this was often either missing, not set, or inaccurate in files we found in the wild, and there are further issues specifically with AVI over a certain length. Other file types have similar problems.
My conclusion was that the only reliable way to get a frame count is to have something like ffmpeg go over the file frame by frame. With the command lines suggested here (which are, if I remember correctly, close to what I used) then it tends to be reasonably fast and, as I say, I'm not sure there's much other option if you need a reasonable amount of reliability on arbitrary files.
If you're in a situation where all your files come from a known source and you are confident they will always have frame count headers that will always be accurate, great, but otherwise I'd recommend doing roughly what's been suggested here.
P
    On Tuesday, 9 March 2021, 10:54:09 GMT, Peter White <peter.white at posteo.net> wrote:  
Unless it happens to be one of those special cases that don't have that
info in their metadata, like matroska:


  


More information about the ffmpeg-user mailing list