FFMpeg encoding error: "height not divisible by 2" - Recommended dimesion 1680 x ??? with aspect 16:9

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

FFMpeg encoding error: "height not divisible by 2" - Recommended dimesion 1680 x ??? with aspect 16:9

Ben Stover
I wanted to encode (and resize) an existing MP4 file into a new MP4 video and a width of 1680 * ... and an aspect ratio of 16:9
The used codec is H.264

Since the calculated height therefore is (1680/16)*9=945 I entered this for the ffmpeg command and got an error:

"height not divisible by 2"

Hmm, can this really be?

What is the recommended height otherwise?

Is there no auto-adjustment in ffmpeg?

Ben
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: FFMpeg encoding error: "height not divisible by 2" - Recommended dimesion 1680 x ??? with aspect 16:9

He Lei
The encoder needs multiples of 2. It better be a multiple of 16.
You can create a black background,   center over the background use the source image.
This will not distort the image.

black  = yuv(0, 128, 128);


//=========================
src_ratio = src_w / src_h;                //ratio of source
dst_ratio = 16.0 / 9;                         //ratio of destination

if(src_ratio > dst_ratio){
  bg_w = src_w;                               //width of background
  bg_h = (int)(bg_w / dst_ratio);      //height of background
  bg_h += bg_h % 2;                       //make it a multiple of 2
}else{
  bg_h = src_h;
  bg_w = (int)(bg_h * dst_ratio);
  bg_w += bg_w % 2;                       //make it a multiple of 2
}

overlay_x = (bg_w - src_w) / 2; //overlay_x  and overlay_y always have one equal to 0
overlay_y = (bg_h - src_h) / 2;


then:
1,create background with size(bg_w, bg_h);
2,overlay to (overlay_x, overlay_y) with the source;
3,encode


LeiHe
[hidden email]<mailto:[hidden email]>



在 2018年10月22日,下午3:32,Ben <[hidden email]<mailto:[hidden email]>> 写道:

I wanted to encode (and resize) an existing MP4 file into a new MP4 video and a width of 1680 * ... and an aspect ratio of 16:9
The used codec is H.264

Since the calculated height therefore is (1680/16)*9=945 I entered this for the ffmpeg command and got an error:

"height not divisible by 2"

Hmm, can this really be?

What is the recommended height otherwise?

Is there no auto-adjustment in ffmpeg?

Ben
_______________________________________________
ffmpeg-user mailing list
[hidden email]<mailto:[hidden email]>
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: FFMpeg encoding error: "height not divisible by 2" - Recommended dimesion 1680 x ??? with aspect 16:9

Moritz Barsnick
In reply to this post by Ben Stover
On Mon, Oct 22, 2018 at 09:32:57 +0200, Ben wrote:
> I wanted to encode (and resize) an existing MP4 file into a new MP4 video and a width of 1680 * ... and an aspect ratio of 16:9
> The used codec is H.264
>
> Since the calculated height therefore is (1680/16)*9=945 I entered this for the ffmpeg command and got an error:
>
> "height not divisible by 2"
> Hmm, can this really be?

Yes, certain operations and codecs have such requirements. For example
the very common H.264 with yuv420p colorspace.

> What is the recommended height otherwise?

Some codecs even encode more efficiently when the resolution is
divisible by 4, 8 or possibly even 16. In your case, just choose a
height divisible by two.

> Is there no auto-adjustment in ffmpeg?

No, but if you use the scale filter (or others using the same size
syntax), you can let ffmpeg do the math for you:

Resize while keeping input aspect ratio, but divisible by 2:

$ ffmpeg [...] -vf scale=1680:-2 [...]

If you want to be explicit about 16:9 (and let ffmpeg calculate 16/9):

$ ffmpeg [...] -vf "scale=trunc(1680/2)*2:trunc(1680*9/16/2)*2"

There are some other nice suggestions in this StackOverflow topic:
https://stackoverflow.com/q/20847674/3974309

Cheers,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".