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 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?
-v error: this is a neat trick to hide the banner information printed by ffprobe (read more about this here)
-select streams v:0is used to target the first video stream (more information here). You can modify suitably for your use case.
-count_framesas the name suggests, gives you a count of the number of frames in the video.
nb_read_framesis the number of frames returned by the decoder.
streamis 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
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!