[FFmpeg-devel] [PATCH] nvenc: Compensate for hardware trying to mess with aspect ratio of DVD content.
Nicolas George
george at nsup.org
Sat Jan 17 20:47:51 CET 2015
L'octidi 28 nivôse, an CCXXIII, Philip Langdale a écrit :
> There is a long sad story behind all this, but it's somewhat ambiguous as to
> whether DVD content should be treated as 720 pixels wide or 704 pixels, with
> 16 pixels cut off. If you decide is should be 704 pixels wide, you need to
> adjust the sample aspect ratio to keep the final display aspect ratio correct.
>
> For reasons we are not privy too, nvidia decided that the nvenc encoder should
> apply this aspect correction, whether you want it to or not. (I guess there
> might be a flag for it, but if there is it's not documented). So, if you want
> to transcode DVD content at the original size, you need to adjust the aspect
> ratio information you pass to the encoder to compensate for their 'correction'.
>
> This 'correction' is only applied to 720x480 and 720x576 content - and it does
> so regardless of the input aspect ratio.
Thanks for testing.
> ---
> libavcodec/nvenc.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index efa3f04..a51ada2 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -587,6 +587,13 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
> ctx->init_encode_params.darWidth = avctx->width;
> }
>
> + // Compensate for hardware assuming playback will be at 704 pixel width.
Nit: de-compensate for buggy encoders that compensate for...
> + if (avctx->width == 720 &&
> + (avctx->height == 480 || avctx->height == 576)) {
> + ctx->init_encode_params.darWidth *= 44;
> + ctx->init_encode_params.darHeight *= 45;
> + }
Here, and also in Timo's patch, I would advice to use lavu's rational
operators: they will handle overflow better and reduce the result.
> +
> ctx->init_encode_params.frameRateNum = avctx->time_base.den;
> ctx->init_encode_params.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame;
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150117/f3475529/attachment.asc>
More information about the ffmpeg-devel
mailing list