7

I have a toolchain that produces frames that are usually 1920x1080, but occasionally 1919x1080 or 1920x1079. (Yes, this is a bug. Please read on.) When ffmpeg encodes a video from it, with a command like

ffmpeg -y -r 30 -i foo/%04d.png -vcodec h264 out.mp4

then it prints remarks like

Input stream #0:0 frame changed from size:1919x1080 fmt:rgb24 to size:1920x1080 fmt:rgb24

but those frames, rather than being resized and included in out.mp4, are omitted from out.mp4.

Can those frames be included? I found no mention of nonconstant frame size on forums and in documentation, but ffmpeg itself here claims to resize the frame. (The remark is printed at line 1688 of ffmpeg.c. There, a flag resample_changed is set, which causes the width and height fields of InputStream *ist to be corrected.)

David Elliman may be reporting similar behavior in an answer to https://stackoverflow.com/questions/18043841/ffmpeg-missing-image-frames-in-generated-video-from-images?rq=1 .

2
  • The best elaborated answer seems to be this one: superuser.com/questions/547296/… which adds black borders to the videos of different frame sizes to avoid stretching (i.e. avoid changing the aspect ratio of the videos).
    – erik
    Jun 4, 2016 at 11:05
  • Pillar- or letter-boxing is appropriate when frame size changes a lot, but not in this case, when it changes by one or two pixels. Then, flashing black borders would be distracting. Jun 6, 2016 at 15:33

3 Answers 3

5

Perhaps the scale video filter can provide what you're looking for:

ffmpeg -r 30 -i foo/%04d.png -vf "scale=1920:1080,format=yuv420p" -codec:v libx264 out.mp4

This will force a size of 1920x1080 for each frame. This may result in a slightly stretched or squished image if your weird sized inputs are simply cropped instead of scaled incorrectly. If that is the case the consider using the pad video filter instead but be aware that it will result in a solid colored bar to compensate for the missing pixels.

scale also accepts various functions if you want to get fancy with it. See Resizing videos with ffmpeg to fit into static sized player for an example.

I added format=yuv420p because, with an RGB input for libx264, ffmpeg will attempt to avoid chroma subsampling resulting in YUV 4:4:4 planar pixel format which most players can not decode.

1

Try omitting the -r 30 parameter for the input framerate and use -framerate 30 for the output framerate instead. I had the same problem and that worked for me.

0

You might have to specify a scale mode for the resizing to work. I grabbed this from my implementation.

--custom-anamorphic --display-width 1920  --keep-display-aspect --modulus 8 --crop 0:0:0:0
5
  • Has this to do with ffmpeg? I don’t think so. Or tell me please how to use it with ffmpeg.
    – erik
    Jun 2, 2016 at 16:35
  • you can run any of these commands from the command line. any GUI you installed is a flavor of ffmpeg ( a wrapper around it). Jun 2, 2016 at 16:44
  • Which version of ffmpeg do you think has these command line options? I couldn’t find a help file explaining the options you listed.
    – erik
    Jun 2, 2016 at 16:56
  • 1
    Instead of just posting a link, you could have explained: Your answer uses Handbrake instead of ffmpeg. Has nothing to do with ffmpeg, except that this (Handbrake) is a tool which may also use ffmpeg as backend.
    – erik
    Jun 25, 2016 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .