FFmpeg drops frames when encoding a png image sequence into an x264 mp4 video
Solution 1:
Problem solved.
By looking at the console output, it seems that the default framerate of the input sequence is 25 fps:
Input #0, image2, from 'frame%04d.png':
Duration: 00:00:06.40, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, rgb24, 1920x1080, 25 fps, 25 tbr, 25 tbn, 25 tbc
From the documentation:
To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps:
ffmpeg -r 1 -i input.m2v -r 24 output.avi
So, all I needed to do just to add another -r 24
:
ffmpeg
-r 24
-i frame%04d.png -r 24 out.mp4
Solution 2:
Another cause of dropped frames is .png's whose format varies. For example, .png's created from ImageMagick's convert
command are normally "color RGB", but ones with fewer than 256 colors are silently optimized into "colormap" or palette, to reduce file size. When ffmpeg encounters a change from one to the other, it starts dropping frames:
Input stream #0:0 frame changed from size:1280x720 fmt:rgb24 to size:1280x720 fmt:pal8
Input stream #0:0 frame changed from size:1280x720 fmt:pal8 to size:1280x720 fmt:rgb24
To avoid dropping such frames, convert -define png:color-type=2
.