Why total frame count is different in ffmpeg than ffprobe?

7

1

I wanted total frame count of video so that i use below ffprobe command :

ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=noprint_wrappers=1 100P.mp4

and i get output below

output of ffprobe

in above output i get 559 frames

then i use same video to add watermark on it and i use below command:

ffmpeg -i 100P.mp4 -i mt.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy -preset ultrafast output.mp4

i get output like this:

output of ffmpeg

and in above image, after adding watermark i get 605 frames

so my question is why i am getting different frame count in ffmpeg and ffprobe?

Milan Tejani

Posted 2019-12-26T08:35:36.700

Reputation: 246

4Just FYI: x264 -preset ultrafast is only a bit fast but much worse quality (per bitrate) than -preset veryfast. That's the fastest preset you should normally consider for anything except lossless -qp 0. (And x264 is so fast that you should normally use at least medium if not slower or veryslow). Ultrafast is so bad that even with high bitrate you get ugliness. If you need to disable CABAC, B-frames, and/or 8x8 DCT for some reason, do that with profile main or baseline, not by destroying your video quality as well with subme=0 – Peter Cordes – 2019-12-26T22:09:25.630

Answers

22

FFmpeg, by default, sets constant frame rate mode for MP4 output. When the input stream is VFR, ffmpeg will duplicate or drop frames to generate a CFR stream. In the output stats, to the right of frame=605, you can see dup=46, which indicates that ffmpeg added 46 duplicated frames. The short version is this happens when two input frames are further apart than 1/FPS seconds, where FPS represents the output frame rate. The output frame rate is set to the detected input framerate (the tbr value), if not expressly set by the user.

Add -vsync vfr to prevent frame duplication.

Gyan

Posted 2019-12-26T08:35:36.700

Reputation: 21 016

3shouldn't you use -vsync passthrough to get the exact number of frames as reported by ffprobe? – hanshenrik – 2019-12-26T21:19:50.880

Yes, you should but those could include frames with identical timestamps. -vsync vfr will drop those. – Gyan – 2019-12-27T17:08:17.823

and when vfr drop those, i guess it will no longer match the number of frames as reported by ffprobe – hanshenrik – 2019-12-27T17:20:50.397

Correct. The OP is about why the counts are different, now how to get them to match :). My vsync statement is just a tip to avoid increasing count. – Gyan – 2019-12-27T17:24:10.547

1Whenever you set -vsync vfr (and you pretty much always want to set that) you might also want to set -enc_time_base -1, otherwise ffmpeg screws up the presentation timestamps. – AndreKR – 2019-12-27T19:07:22.260