[FFmpeg-cvslog] avfilter/vf_scale: set correct AVFrame SAR if reset_sar=1

Niklas Haas git at videolan.org
Mon Jun 16 21:45:00 EEST 2025


ffmpeg | branch: master | Niklas Haas <git at haasn.dev> | Mon Jun 16 19:48:11 2025 +0200| [04ceabe2ba4cafa9ebd663409795c0398bf89063] | committer: Niklas Haas

avfilter/vf_scale: set correct AVFrame SAR if reset_sar=1

This otherwise generates an inconsistency between the frame state and the
link state, since the link state is set to 1:1 explicitly when `reset_sar`
is enabled, but this line of code unconditionally overwrote the output
frame SAR with the value that would be computed in the absence of `reset_sar`.

cf. vf_scale_cuda, which does this correctly

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

 libavfilter/vf_scale.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 62aa872c77..aec765b441 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -854,10 +854,14 @@ scale:
                                            AV_SIDE_DATA_PROP_COLOR_DEPENDENT);
     }
 
-    av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
-              (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
-              (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
-              INT_MAX);
+    if (scale->reset_sar) {
+        out->sample_aspect_ratio = outlink->sample_aspect_ratio;
+    } else {
+        av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
+                (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
+                (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
+                INT_MAX);
+    }
 
     if (sws_is_noop(out, in)) {
         av_frame_free(&out);



More information about the ffmpeg-cvslog mailing list