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 .

3 Answers3

6

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.

llogan
  • 63,280
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.

Ben N
  • 42,308
pelagos
  • 21
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
FlavorScape
  • 199
  • 1
  • 1
  • 9