6

i tried to scale the video to 375x500 using ffmpeg.

ffmpeg -i input.mp4 -s 375x500 -c:a copy output.mp4

Getting this error, [libx264 @ 0x5639d358ad60] width not divisible by 2 (375x500) 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.

I tried so many commands but i didnt get my solution.

  • Hi @KarthiKeyan, your question may be a duplicate. You can find your answer [in this other post](https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2). Basically, as explained on the shared link, when scaling the video you want to keep the aspect ratio and may use a negative number to have one of the dimensions automatically calculated.. – diogoslima Mar 21 '20 at 14:37
  • @diogoslima I tried those commands but I don't want to calculate the width/height automatically, I have fixed width and height, I need to scale the video to exact dimensions. – Karthikeyan Balusamy Mar 21 '20 at 14:45
  • “Width not divisible by 2” is pretty clear. Change the width to 376. – szatmary Mar 21 '20 at 16:09

1 Answers1

8

libx264 requires width/height to be divisible by 2 when using the standard yuv420p pixel format. Refer to the many suggestions regarding how to fix the not divisible by 2 error with scale/pad/crop:

However, if you must have exactly 375x500 then you have to use a pixel format that supports this size:

ffmpeg -i input.mp4 -vf "format=yuv444p,scale=375:500" -c:a copy output.mp4

Drawback is that almost no player or device will be able to play it (unless it uses FFmpeg).

See the format and scale filter documentation and the output of ffmpeg -pix_fmts for more info.

llogan
  • 121,796
  • 28
  • 232
  • 243