[FFmpeg-devel] [PATCH] nvenc: Compensate for hardware trying to mess with aspect ratio of DVD content.

Philip Langdale philipl at overt.org
Sat Jan 17 20:35:41 CET 2015


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.
---
 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.
+    if (avctx->width == 720 &&
+        (avctx->height == 480 || avctx->height == 576)) {
+      ctx->init_encode_params.darWidth *= 44;
+      ctx->init_encode_params.darHeight *= 45;
+    }
+
     ctx->init_encode_params.frameRateNum = avctx->time_base.den;
     ctx->init_encode_params.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame;
 
-- 
2.1.0



More information about the ffmpeg-devel mailing list