I want to make a simple video with a jpeg image and a mp3 audio file using ffmpeg. I used this command:

ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4

and get this error:

[swscaler @ 0x555f60538b40] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x555f60594d40] height not divisible by 2 (550x765)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

I can't make sense of it. Could you correct the command for me?

1 Answer 1



ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -vf "scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p" -shortest -movflags +faststart out.mp4

The scale filter example is a fancy way of making the width and height to be divisible by 2 which is needed for this particular encoder when outputting YUV 4:2:0 (4:2:2 and 4:4:4 are not supported by most players, so that is why you see so many examples using yuv420p).

A simpler method is to crop or scale like crop=550:764, but the above command will work with any input size.

  • Thanks a bunch. That worked. What would the command look like if I watned to place two images side by side?
    – H3R3T1K
    Jun 16, 2020 at 7:59
  • @H3R3T1K ffmpeg -loop 1 -i left.jpg -loop 1 -i right.jpg -i audio.mp3 -filter_complex "[0][1]hstack=inputs=2,scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p[v]" -map "[v]" -map 2:a -c:v libx264 -tune stillimage -c:a aac -b:a 192k -shortest -movflags +faststart out.mp4
    – llogan
    Jun 16, 2020 at 21:06
  • @IIogan [swscaler @ 0x563d38f43f00] deprecated pixel format used, make sure you did set range correctly [Parsed_hstack_0 @ 0x563d390c9d00] Input 1 height 662 does not match input 0 height 765. [Parsed_hstack_0 @ 0x563d390c9d00] Failed to configure output pad on Parsed_hstack_0 Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #1:0 Conversion failed!
    – H3R3T1K
    Jun 20, 2020 at 9:56
  • @H3R3T1K I was assuming each input was the same height. Use the scale filter to make them the same height.
    – llogan
    Jun 20, 2020 at 20:57
  • 1
    @HashimAziz If you already know one of the dimensions you need then your solution is just fine (and is what I usually do). The solution in the answer is just a precaution so users can copy and paste the answer for any arbitrary sized input without having to know anything or deal with making the width or height divisible by 2.
    – llogan
    Mar 9, 2021 at 20:28

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.