Extract Frame Count Using ffprobe (Number of Frames in a Video)

In this quick tutorial, we’ll teach you how to extract the number of frames (of frame count) in a video using ffprobe, an utility written using the FFmpeg video processing library. To learn more about these tools, please explore all our FFmpeg articles and do check out our deep dive into ffprobe.

frame count or count the number of frames  using ffmpeg or ffprobe

Frame Count using ffprobe

It is very easy to count the number of frames in a video using the ffprobe tool.

ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv BigBuckBunny.mp4

What does this command do?

BuyDRM
  • -v error : this is a neat trick to hide the banner information printed by ffprobe (read more about this here)
  • -select streams v:0 is used to target the first video stream (more information here). You can modify suitably for your use case.
  • -count_frames as the name suggests, gives you a count of the number of frames in the video.
  • nb_read_frames is the number of frames returned by the decoder. stream is a selector that allows you to narrow down on what data to print. Here is more information on ffprobe’s specifiers.

Running this command will instruct ffprobe to print the number of frames in the video. It’s as simple as that!

ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames  Big_Buck_Bunny_1080_10s_20MB.mp4

Output
stream,300

If you want only the number and not the specifier (stream), then you can modify the commandline as instructed here. This will ensure that the keys are not printed and only the value is output by ffprobe.

ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format default=nokey=1:noprint_wrappers=1 Big_Buck_Bunny_1080_10s_20MB.mp4

Conclusion

I hope you found this quick tutorial on the use of ffprobe to count the number of frames in a video to be useful. Please subscribe to OTTVerse for more such articles, deep-dives, and interviews. Until next time, happy streaming!

Be the first to comment

Leave a Reply

Your email address will not be published.


*