Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 ffmpeg missing image frames in generated video from images .

share|improve this question

migrated from stackoverflow.com Aug 6 '13 at 23:02

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer

Whether or not this is a bug in FFmpeg or something FFmpeg should better document support or lack of support for, I don't really see the programming question. You should fix your bug that's generating incorrect frame sizes and be thankful that FFmpeg alerted you to this issue, since silently "fixing" them by expanding or resampling may had led to tiny "jitter" in the encoded video and left you with subtly-defective output video and poor compression quality.

share|improve this answer
    
I see FFMpeg (compiled version) as an API that happens to be accessed via a CLI, making it an obvious programming question. –  FlavorScape Aug 6 '13 at 19:39
1  
@FlavorScape: FFmpeg CLI is not API. libav* is API. The CLI question belongs to SuperUser, there is nothing for programming here. –  Roman R. Aug 6 '13 at 20:38
    
It's really a matter of nomenclature. In essence they are the same. CLI, API (and Web GUI) are doing the same thing behind the scenes: changing values of configurable variables and data structures. It doesn’t matter which mechanism you use to set a variable value or insert a new data structure in a linked list – no API will save the day if the software you’re interacting with doesn’t support the functionality you need. -blog.ipspace.net/2013/06/… –  FlavorScape Aug 6 '13 at 21:13
    
My bad. Based on the answers so far, the question as asked is indeed a better fit for SuperUser.com, where I have an account. (I don't think I can self-migrate it.) –  Camille Goudeseune Aug 6 '13 at 22:26

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.