7

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?

  • 4
    Just 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 Dec 26 '19 at 22:09
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.

| improve this answer | |
  • 3
    shouldn't you use -vsync passthrough to get the exact number of frames as reported by ffprobe? – hanshenrik Dec 26 '19 at 21:19
  • Yes, you should but those could include frames with identical timestamps. -vsync vfr will drop those. – Gyan Dec 27 '19 at 17:08
  • and when vfr drop those, i guess it will no longer match the number of frames as reported by ffprobe – hanshenrik Dec 27 '19 at 17:20
  • 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 Dec 27 '19 at 17:24
  • 2
    Whenever 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 Dec 27 '19 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.