From e7fbdda64e2797c81a11c05b996dbb120c98b8c9 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Thu, 10 Nov 2022 13:05:59 +0100 Subject: avcodec/nvenc: fix AV1 darWidth/Height calculation nvenc uses the darWidth/Height fields for the AV1 render_width/height instead, so a different calculation is needed. --- libavcodec/nvenc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 2583ec2912..b9edc0e26d 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -34,6 +34,7 @@ #include "libavutil/imgutils.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" +#include "libavutil/mathematics.h" #include "atsc_a53.h" #include "encode.h" #include "internal.h" @@ -1454,6 +1455,25 @@ static void compute_dar(AVCodecContext *avctx, int *dw, int *dh) { sw = avctx->width; sh = avctx->height; +#if CONFIG_AV1_NVENC_ENCODER + if (avctx->codec->id == AV_CODEC_ID_AV1) { + /* For AV1 we actually need to calculate the render width/height, not the dar */ + if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0 + && avctx->sample_aspect_ratio.num != avctx->sample_aspect_ratio.den) + { + if (avctx->sample_aspect_ratio.num > avctx->sample_aspect_ratio.den) { + sw = av_rescale(sw, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); + } else { + sh = av_rescale(sh, avctx->sample_aspect_ratio.den, avctx->sample_aspect_ratio.num); + } + } + + *dw = sw; + *dh = sh; + return; + } +#endif + if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) { sw *= avctx->sample_aspect_ratio.num; sh *= avctx->sample_aspect_ratio.den; -- cgit v1.2.3