3

What is the default output frame rate chosen by ffmpeg to encode MP4s?
Where is this specified on the man page?

My input video stats are:

  • r_frame_rate=120/1
  • avg_frame_rate=31230000/1042111
  • duration=11.579011
  • nb_frames=347

After (demuxing, decoding) splitting (rescaling, encoding and muxing) the video stream I end up with has the following stats:

  • r_frame_rate=120/1
  • avg_frame_rate=120/1
  • duration=9.575000
  • nb_frames=1149

I started with 347 frames and ended up with 1149 (should have been 287). The input average fps was 29.97 and now I end up with 120... which was the max fps of the input video. So, I imagine ffmpeg picks the highest one from the input... but is this specified anywhere? How does one go simply matching the input fps? And why does I have a variable fps to begin with?

Hmm... too may questions I guess. Still, is this simply a consequence of this paragraph?

STREAM SELECTION                                                 
       By default, ffmpeg includes only one stream of each type  
       (video, audio, subtitle) present in the input files and   
       adds them to each output file.  It picks the "best" of    
       each based upon the following criteria: for video, it is  
       the stream with the highest resolution, for audio, it is  
       the stream with the most channels, for subtitles, it is   
       the first subtitle stream. In the case where several      
       streams of the same type rate equally, the stream with the
       lowest index is chosen.                                   
7

r_frame_rate is "the lowest framerate with which all timestamps can be represented accurately (it is the least common multiple of all framerates in the stream)."

avg_frame_rate is just that: total duration / total # of frames

You can just specify -r 30000/1001 to maintain the average rate (near-abouts). You don't specify which format you're outputting to, but for MP4, ffmpeg defaults to constant-frame rate, where it picks r_frame_rate as the value. It will then duplicate or drop frames to keep that rate. Use -vsync vfr to keep the variable rate.

  • Wow... You're impressive. The first line comes from the FAQ. Any idea where this is mentioned in the man page? Yes, I'm encoding in MP4. Where did you get that info about the constant frame rate picking? I ended up setting -r to the input avg_frame_rate. (My client expect temporal constancy between the frames.) – Atcold Feb 27 '17 at 19:08
  • r_frame_rate is not a CLI option, so I doubt the man pages mention it, although I haven't looked. You have to look in the mp4 muxer source to check the default rate muxing mode. Again, not in the man pages. FFmpeg docs are a work in progress. – Gyan Feb 27 '17 at 19:24
  • Again, impressive. Thank you for sharing your knowledge. – Atcold Feb 27 '17 at 20:27

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.