[FFmpeg-devel] [PATCH 1/4] Correctly set Display Aspect Ratio in nvenc.

Mark Himsley mark at mdsh.com
Wed Jan 7 20:42:42 CET 2015

On 07/01/2015 18:46, Philip Langdale wrote:
> On Wed, 7 Jan 2015 12:13:25 +0100
> Nicolas George <george at nsup.org> wrote:
>> Can you explain the 1024?
>> Anyway, I would suggest to use lavu's rational functions:
>>     AVRational dar = av_mul_q(avctx->sample_aspect_ratio,
>>                               av_make_q(avctx->width, avctx->height));
>>     av_reduce(&dar.num, &dar.den, dar.num, dar.den, MAX);
>>     nvenc_ctx->nvenc_cfg.darWidth  = 1024 * dar.num;
>>     nvenc_ctx->nvenc_cfg.darHeight = 1045 * dar.den;
>> (including the *1.02 in the 1024 constant to avoid floating point
>> operations, but I am very suspicious about that 1.02)
>> Regards,
> Honestly, I don't understand what the encoder is doing at this point.
> The 1.02 seems to be the 'correct' scale factor for a PAL DVD,


says 1.094

> but is
> incorrect for anything else. I used 1024 to avoid the floating point
> problem, but you are right that pre-multiplication is a better way to
> handle that. Right now I'm playing around with an NTSC DVD and I can't
> find the right magic to stop it mangling the aspect ratio.

Where 'PAL' (I use the term loosely to imply 25 702x576 interlaced
pictures in a 720x576 frame) is:

768x576 active square pixels in a 788x576 square pixel frame for 4:3
1024x576 active square pixels in a 1050x576 square pixel frame for 16:9

for the full frame 'NTSC' (loosely 30000/1001 710.85x486 interlaced
pictures in a 720x486 frame) is approximately:

648x486 active square pixels in a 656.34x486 square pixel frame for 4:3
864x486 active square pixels in a 875.12x486 square pixel frame for 16:9

Although, I'm not sure that information is going to help you :-(

> At this point, I'm not convinced that darWidth and darHeight are even
> representing the display presentation size at all. Hopefully Agatha can
> understand what's going on here.
> --phil
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

More information about the ffmpeg-devel mailing list