[FFmpeg-devel] [PATCH 1/4] Correctly set Display Aspect Ratio in nvenc.
Philip Langdale
philipl at overt.org
Tue Jan 6 08:36:15 CET 2015
The encoder writes the display aspect ratio into the output frames, which a
good player will respect, so let's make sure it's correct.
The 1.02 scale factor is black magic, but produces correct results. I don't
know what nvenc is doing.
Signed-off-by: Philip Langdale <philipl at overt.org>
---
libavcodec/libnvenc.c | 2 ++
libavcodec/libnvenc.h | 2 ++
libavcodec/nvencoder.c | 8 ++++----
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/libavcodec/libnvenc.c b/libavcodec/libnvenc.c
index d81e04a..6ba150e 100644
--- a/libavcodec/libnvenc.c
+++ b/libavcodec/libnvenc.c
@@ -129,6 +129,8 @@ static av_cold int ff_libnvenc_init(AVCodecContext *avctx)
// Basic
nvenc_ctx->nvenc_cfg.width = avctx->width;
nvenc_ctx->nvenc_cfg.height = avctx->height;
+ nvenc_ctx->nvenc_cfg.darWidth = 1024 * avctx->width * avctx->sample_aspect_ratio.num / avctx->sample_aspect_ratio.den;
+ nvenc_ctx->nvenc_cfg.darHeight = 1024 * avctx->height * 1.02;
nvenc_ctx->nvenc_cfg.frameRateNum = avctx->time_base.den;
nvenc_ctx->nvenc_cfg.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame;
diff --git a/libavcodec/libnvenc.h b/libavcodec/libnvenc.h
index 42718a2..63b5d67 100644
--- a/libavcodec/libnvenc.h
+++ b/libavcodec/libnvenc.h
@@ -48,6 +48,8 @@ typedef struct nvenc_cfg_t
// Basic
uint32_t width;
uint32_t height;
+ uint32_t darWidth;
+ uint32_t darHeight;
uint32_t frameRateNum;
uint32_t frameRateDen;
diff --git a/libavcodec/nvencoder.c b/libavcodec/nvencoder.c
index 06eb68b..f1d432f 100644
--- a/libavcodec/nvencoder.c
+++ b/libavcodec/nvencoder.c
@@ -517,8 +517,8 @@ static bool initialize(nvencoder_t *nvenc, nvenc_cfg_t *nvenc_cfg)
nvenc->init_params.presetGUID = NV_ENC_PRESET_HQ_GUID;
nvenc->init_params.encodeWidth = nvenc_cfg->width;
nvenc->init_params.encodeHeight = nvenc_cfg->height;
- nvenc->init_params.darWidth = nvenc_cfg->width;
- nvenc->init_params.darHeight = nvenc_cfg->height;
+ nvenc->init_params.darWidth = nvenc_cfg->darWidth;
+ nvenc->init_params.darHeight = nvenc_cfg->darHeight;
nvenc->init_params.frameRateNum = nvenc_cfg->frameRateNum;
nvenc->init_params.frameRateDen = nvenc_cfg->frameRateDen;
nvenc->init_params.enableEncodeAsync = 0;
@@ -696,8 +696,8 @@ static bool reconfig(nvencoder_t *nvenc, nvenc_cfg_t *nvenc_cfg)
// Update initial encoder parameters that likely changed
nvenc->init_params.encodeWidth = nvenc_cfg->width;
nvenc->init_params.encodeHeight = nvenc_cfg->height;
- nvenc->init_params.darWidth = nvenc_cfg->width;
- nvenc->init_params.darWidth = nvenc_cfg->height;
+ nvenc->init_params.darWidth = nvenc_cfg->darWidth;
+ nvenc->init_params.darHeight = nvenc_cfg->darHeight;
nvenc->init_params.frameRateNum = nvenc_cfg->frameRateNum;
nvenc->init_params.frameRateDen = nvenc_cfg->frameRateDen;
nvenc->init_params.encodeConfig->rcParams.averageBitRate = nvenc_cfg->avgBitRate;
--
2.1.0
More information about the ffmpeg-devel
mailing list