21

I have no knowledge whatsoever about video encoding, I have an application written in OpenGL and I am saving the frames it generated into png images. The frames from my app are at 7 FPS and I am trying to create a video from those.

To that purpose I use ffmpeg like this

ffmpeg -framerate 30 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

which was taken from this site, however I was wondering if it is possible to have a video that shows the animation at 30 FPS?

21

I'm using the below code to do the same thing.

ffmpeg -framerate 30 -i img%03d.png -c:v libx264 -pix_fmt yuv420p -crf 23 output.mp4

Breaking down the command:

ffmpeg             <- call ffmpeg
  -framerate 30    <- set the input framerate to 30
  -i img%03d.png   <- read PNG images with filename img001, img002, img003, etc..
                     img can be changed to another prefix
                     %03d can be changed to %04d for 0001, %05d for 00001 formats, etc...
  -c:v libx264     <- Set the codec to libx264
  -pix_fmt yuv420p <- Set the pixel format to planar YUV 4:2:0, 12bpp
  -crf 23          <- set the Constant Rate Factor to 23 (default value)
  -output.mp4      <- the output filename

This reads the input at 30 fps (the -framerate 30 option) and encodes it using the libx264 codec with constant rate factor of 23 (the -crf 23 option).

26

There are two frame rates to consider: the input and the output.

By default the input frame rate is 25, and the output will use the same frame rate as the input unless you tell it otherwise.

Same frame rate for input and output

If you want to input and output to have the same frame rate, then just provide the input frame rate. This example will set a frame rate of 30000/1001 (NTSC video):

ffmpeg -framerate 30000/1001 -i input output.mp4
  • Alternatively, in this example, you could use ntsc instead of 30000/1001, but don't use 29.97 because that is not accurate or correct. See other frame rate aliases.

  • Because the default input frame rate is 25, and if you only set an output frame rate, then frames will be dropped or duplicated to compensate. That is why the input frame rate is set in this situation.

Different frame rate for input and output

Sometimes you may want the input frame rate and output frame rate to differ. For example, you may want to input the frames at a certain rate, and then duplicate or drop frames so the output has a different frame rate. You may want to do this due to compatibility issues with your output format container, your player, and/or your device:

ffmpeg -framerate 10 -i input -r 25 output.mp4
  • In this example frames will be duplicated to go from 10 to 25. The console output will tell you if frames are being dropped or duplicated.

  • The image file demuxer uses -framerate, while the output frame rate is set using -r.

  • You may have to add the -pix_fmt yuv420p option in some circumstances if you're outputting H.264 video (the ffmpeg console output will warn you if you do need to). This will use a chroma subsampling scheme that is compatible with all players.

  • 2
    ffmpeg version 3.2.2 tells me: Option framerate not found. :-( – erik Jan 4 '17 at 11:26
  • Yes, you are right. But nevertheless the option -framerate does not exist anymore. I will delete my comment, as it really has nothing to do with converting a series of images to a video with a certain framerate. – erik Jan 4 '17 at 21:24
  • 4
    @erik -framerate does exist. It's used by the image and rawvideo demuxers and some input devices such as x11grab and v4l2. – llogan Jan 4 '17 at 22:33
  • 1
    Where is the option -framerate documented? I've read the man ffmpeg page, but I couldn't find it. Any pointer, perhaps? – Atcold Feb 27 '17 at 17:02
  • 1
    OK, found it... FFMPEG-DEVICES(1). – Atcold Feb 27 '17 at 17:12
1
ffmpeg -framerate 30 -i img%03d.png output.mp4  

will be sufficient in the latest version of ffmpeg.

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.