PR #21038 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21038
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21038.patch

The current logic assumes `s->reset_sar` always resets the SAR, but this
is only true if `force_oar` is actually true as well, meaning that in the
case of `s->reset_sar && !force_oar`, the SAR is incorrectly set to 1:1.

While we could fix this by also forcing `force_oar` for multiple inputs,
that would have unintended consequences when the user explicitly sets the
desired resolution. Instead, pass-through the SAR in this case; matching
the intended behavior of inheriting the SAR from the base layer input.


>From 0ab721603cd708327d70ac9721950778fe2d7b5c Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Fri, 28 Nov 2025 13:43:27 +0100
Subject: [PATCH] avfilter/vf_libplacebo: always pass through SAR when
 stretching

The current logic assumes `s->reset_sar` always resets the SAR, but this
is only true if `force_oar` is actually true as well, meaning that in the
case of `s->reset_sar && !force_oar`, the SAR is incorrectly set to 1:1.

While we could fix this by also forcing `force_oar` for multiple inputs,
that would have unintended consequences when the user explicitly sets the
desired resolution. Instead, pass-through the SAR in this case; matching
the intended behavior of inheriting the SAR from the base layer input.
---
 libavfilter/vf_libplacebo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 42501c51f2..c5085aa7e9 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1507,10 +1507,7 @@ static int libplacebo_config_output(AVFilterLink 
*outlink)
         }
     }
 
-    if (s->reset_sar) {
-        /* SAR is normalized, or we have multiple inputs, set out to 1:1 */
-        outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
-    } else if (inlink->sample_aspect_ratio.num && s->fit_mode == FIT_FILL) {
+    if (inlink->sample_aspect_ratio.num && s->fit_mode == FIT_FILL) {
         /* This is consistent with other scale_* filters, which only
          * set the outlink SAR to be equal to the scale SAR iff the input SAR
          * was set to something nonzero */
@@ -1518,6 +1515,9 @@ static int libplacebo_config_output(AVFilterLink *outlink)
         const AVRational ar_out  = { outlink->w, outlink->h };
         const AVRational stretch = av_div_q(ar_in, ar_out);
         outlink->sample_aspect_ratio = av_mul_q(inlink->sample_aspect_ratio, 
stretch);
+    } else if (s->reset_sar) {
+        /* SAR is normalized, or we have multiple inputs, set out to 1:1 */
+        outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
     } else {
         outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
     }
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to