27

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?

2
26

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).

0
32

Image inputs

Default frame rate for image inputs is 25. You can change it with the -framerate input option. Example for 24 fps:

ffmpeg -framerate 24 -i input_%03d.jpg -vf format=yuv420p output.mp4
  • -vf format=yuv420p (or the legacy alias -pix_fmt yuv420p) will ensure compatible chroma subsampling for MP4. Otherwise, ffmpeg will try to preserve color fidelity, but most players can't handle advanced chroma subsampling.
  • The output will use the same frame rate as the input. So you do not need to set an output frame rate. But there are a few reasons to do so. See Using a different frame rate for image inputs and video output below.

Video inputs

Use the -r output option:

ffmpeg -i input.mp4 -r 25 output.mp4

Using a different frame rate for image inputs and video output

Why? For example, you may want all images to be displayed for 1 second each (1 fps). But most players can't play very low frame rates (about 6 fps or lower). So you can make ffmpeg use a different output frame rate. The output will look like 1 fps, but will actually be a normal frame rate, such as 25 fps.

Example: input images at 1 fps, but make the output 25 fps.

ffmpeg -framerate 1 -i input_%03d.png -r 25 output.mp4
  • Frames will be duplicated or dropped to match the desired output frame rate.
  • The image demuxer uses -framerate, while the output frame rate is set using -r.

Error: Option framerate not found

The -framerate option:

  • Is not a generic option. It doesn't work for everything.
  • Is only an input option.
  • Only works with certain demuxers (including: images, x11grab, rawvideo).
  • You probably only need to use the -r output option. See the Video inputs section above.
8
  • 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
  • 5
    @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
  • 3
    OK, found it... FFMPEG-DEVICES(1). – Atcold Feb 27 '17 at 17:12
2
ffmpeg -framerate 30 -i img%03d.png output.mp4  

will be sufficient in the latest version of ffmpeg.

1
  • Dont forget the -pix_fmt yuv420p or you may end up with files that many software tools don't like: trac.ffmpeg.org/ticket/8856 – bers Aug 19 '20 at 7:18
1

You are talking about video interpolation. There is no way for 7 fps to become 30 fps without video interpolation... Basically you want to get 30fps from the start, in the process of making videos... As video interpolation will take lots of resources and time, and it might be filled with artifacts. I heard you can make a single shot picture into a short movies, with adobe, but lots of manual work there...

1

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.