FPS is defined as number of frames per second. But when I try to calculate FPS using total frames / duration, I get slightly different number than the FPS shown in ffmpeg:
For this video http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4 using ffmpeg, we can get its FPS, duration and total frames:
ffprobe -select_streams v -show_streams ForBiggerFun.mp4 | grep nb_frames
nb_frames=1440
ffmpeg -i ForBiggerFun.mp4
23.98 fps Duration: 00:01:00.07
If we calculate duration per frame using nb_frames, we get fps = nb_frames/Duration = 1440/60.07 = 23.972032628599965, which is different from 23.98
Which value is more reliable? Does the difference means duration of a frame might be different from others (frames are not evenly distributed)?
Note that both the duration and fps are rounded to two decimal places.
To get a more precise reading, run
ffprobe -v 0 -select_streams v -show_entries stream=duration_ts,time_base,nb_frames ForBiggerFun.mp4
which will produce
[STREAM]
time_base=1/48000
duration_ts=2881920
nb_frames=1440
[/STREAM]
Your precise framerate is nb_frames / (duration_ts / time_base)
= 1440 / (2881920 / 48000)
= 23.9840
. Note however that all streams won't have the same duration. Indeed, the audio stream is 30 milliseconds longer, and a player will extend the duration of the video to match that, so arithmetically, effective frame rate is marginally smaller.