ffmpeg | branch: master | Timo Rothenpieler <t...@rothenpieler.org> | Thu Nov 
10 13:05:59 2022 +0100| [e7fbdda64e2797c81a11c05b996dbb120c98b8c9] | committer: 
Timo Rothenpieler

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e7fbdda64e2797c81a11c05b996dbb120c98b8c9
---

 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;

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to