* [FFmpeg-devel] [PATCH] lavfi/vf_libplacebo: simplify SAR normalization
@ 2023-06-20 15:12 Niklas Haas
2023-06-23 13:18 ` Niklas Haas
0 siblings, 1 reply; 2+ messages in thread
From: Niklas Haas @ 2023-06-20 15:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
The old logic was trying to be excessively clever in "deducing" that the
user wanted to stretch/scale the image when ow/oh differed from iw/ih
aspect ratio. But this is almost surely unintended except in
pathological cases, and in those cases users should simply disable
normalize_sar and do all the stretching/scaling logic themselves. This
is especially important in multi-input mode, where the canvas may be
vastly different from the input dimensions of any stream. Also, passing
through input 0 SAR in multi-input mode is arbitrary and nearly useless,
so again force output SAR to 1:1 here.
---
libavfilter/vf_libplacebo.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 0f7c6481925..e58183a5caa 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -160,7 +160,6 @@ typedef struct LibplaceboContext {
// Parsed expressions for input/output crop
AVExpr *crop_x_pexpr, *crop_y_pexpr, *crop_w_pexpr, *crop_h_pexpr;
AVExpr *pos_x_pexpr, *pos_y_pexpr, *pos_w_pexpr, *pos_h_pexpr;
- AVRational target_sar;
float pad_crop_ratio;
float corner_rounding;
int force_original_aspect_ratio;
@@ -795,9 +794,9 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in,
target->crop.y0 = av_expr_eval(s->pos_y_pexpr, s->var_values, NULL);
target->crop.x1 = target->crop.x0 + s->var_values[VAR_POS_W];
target->crop.y1 = target->crop.y0 + s->var_values[VAR_POS_H];
-
- if (s->target_sar.num) {
- float aspect = pl_rect2df_aspect(&target->crop) * av_q2d(s->target_sar);
+ if (s->normalize_sar) {
+ float aspect = pl_rect2df_aspect(&image->crop);
+ aspect *= av_q2d(in->link->sample_aspect_ratio);
pl_rect2df_aspect_set(&target->crop, aspect, s->pad_crop_ratio);
}
}
@@ -1188,7 +1187,6 @@ static int libplacebo_config_output(AVFilterLink *outlink)
const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
AVHWFramesContext *hwfc;
AVVulkanFramesContext *vkfc;
- AVRational scale_sar;
/* Frame dimensions */
RET(ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
@@ -1198,20 +1196,15 @@ static int libplacebo_config_output(AVFilterLink *outlink)
s->force_original_aspect_ratio,
s->force_divisible_by);
- scale_sar = (AVRational){outlink->h * inlink->w, outlink->w * inlink->h};
- if (inlink->sample_aspect_ratio.num)
- scale_sar = av_mul_q(scale_sar, inlink->sample_aspect_ratio);
-
- if (s->normalize_sar) {
- /* Apply all SAR during scaling, so we don't need to set the out SAR */
+ if (s->normalize_sar || s->nb_inputs > 1) {
+ /* SAR is normalized, or we have multiple inputs, set out to 1:1 */
outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
- s->target_sar = scale_sar;
} else {
/* 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 */
if (inlink->sample_aspect_ratio.num)
- outlink->sample_aspect_ratio = scale_sar;
+ outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
}
/* Frame rate */
--
2.41.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavfi/vf_libplacebo: simplify SAR normalization
2023-06-20 15:12 [FFmpeg-devel] [PATCH] lavfi/vf_libplacebo: simplify SAR normalization Niklas Haas
@ 2023-06-23 13:18 ` Niklas Haas
0 siblings, 0 replies; 2+ messages in thread
From: Niklas Haas @ 2023-06-23 13:18 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
On Tue, 20 Jun 2023 17:12:48 +0200 Niklas Haas <ffmpeg@haasn.xyz> wrote:
> From: Niklas Haas <git@haasn.dev>
>
> The old logic was trying to be excessively clever in "deducing" that the
> user wanted to stretch/scale the image when ow/oh differed from iw/ih
> aspect ratio. But this is almost surely unintended except in
> pathological cases, and in those cases users should simply disable
> normalize_sar and do all the stretching/scaling logic themselves. This
> is especially important in multi-input mode, where the canvas may be
> vastly different from the input dimensions of any stream. Also, passing
> through input 0 SAR in multi-input mode is arbitrary and nearly useless,
> so again force output SAR to 1:1 here.
> ---
> libavfilter/vf_libplacebo.c | 19 ++++++-------------
> 1 file changed, 6 insertions(+), 13 deletions(-)
>
> diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> index 0f7c6481925..e58183a5caa 100644
> --- a/libavfilter/vf_libplacebo.c
> +++ b/libavfilter/vf_libplacebo.c
> @@ -160,7 +160,6 @@ typedef struct LibplaceboContext {
> // Parsed expressions for input/output crop
> AVExpr *crop_x_pexpr, *crop_y_pexpr, *crop_w_pexpr, *crop_h_pexpr;
> AVExpr *pos_x_pexpr, *pos_y_pexpr, *pos_w_pexpr, *pos_h_pexpr;
> - AVRational target_sar;
> float pad_crop_ratio;
> float corner_rounding;
> int force_original_aspect_ratio;
> @@ -795,9 +794,9 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in,
> target->crop.y0 = av_expr_eval(s->pos_y_pexpr, s->var_values, NULL);
> target->crop.x1 = target->crop.x0 + s->var_values[VAR_POS_W];
> target->crop.y1 = target->crop.y0 + s->var_values[VAR_POS_H];
> -
> - if (s->target_sar.num) {
> - float aspect = pl_rect2df_aspect(&target->crop) * av_q2d(s->target_sar);
> + if (s->normalize_sar) {
> + float aspect = pl_rect2df_aspect(&image->crop);
> + aspect *= av_q2d(in->link->sample_aspect_ratio);
> pl_rect2df_aspect_set(&target->crop, aspect, s->pad_crop_ratio);
> }
> }
> @@ -1188,7 +1187,6 @@ static int libplacebo_config_output(AVFilterLink *outlink)
> const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
> AVHWFramesContext *hwfc;
> AVVulkanFramesContext *vkfc;
> - AVRational scale_sar;
>
> /* Frame dimensions */
> RET(ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
> @@ -1198,20 +1196,15 @@ static int libplacebo_config_output(AVFilterLink *outlink)
> s->force_original_aspect_ratio,
> s->force_divisible_by);
>
> - scale_sar = (AVRational){outlink->h * inlink->w, outlink->w * inlink->h};
> - if (inlink->sample_aspect_ratio.num)
> - scale_sar = av_mul_q(scale_sar, inlink->sample_aspect_ratio);
> -
> - if (s->normalize_sar) {
> - /* Apply all SAR during scaling, so we don't need to set the out SAR */
> + if (s->normalize_sar || s->nb_inputs > 1) {
> + /* SAR is normalized, or we have multiple inputs, set out to 1:1 */
> outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
> - s->target_sar = scale_sar;
> } else {
> /* 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 */
> if (inlink->sample_aspect_ratio.num)
> - outlink->sample_aspect_ratio = scale_sar;
> + outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
> }
>
> /* Frame rate */
> --
> 2.41.0
>
Merged as 5fdb12d6a06.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-23 13:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 15:12 [FFmpeg-devel] [PATCH] lavfi/vf_libplacebo: simplify SAR normalization Niklas Haas
2023-06-23 13:18 ` Niklas Haas
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git