diff options
author | Timo Rothenpieler <timo@rothenpieler.org> | 2022-11-10 13:05:59 +0100 |
---|---|---|
committer | Timo Rothenpieler <timo@rothenpieler.org> | 2022-11-10 14:51:31 +0100 |
commit | e7fbdda64e2797c81a11c05b996dbb120c98b8c9 (patch) | |
tree | 09f1cdf2b51096804d82cb445f27ff6b6870ad44 | |
parent | 05721c5df8595f086667a638b13d3fc39684bc21 (diff) | |
download | ffmpeg-e7fbdda64e2797c81a11c05b996dbb120c98b8c9.tar.gz |
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.
-rw-r--r-- | libavcodec/nvenc.c | 20 |
1 files changed, 20 insertions, 0 deletions
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; |