* [FFmpeg-devel] [PATCH] avfilter/vpp_amf: add option reset_sar
@ 2025-02-10 12:23 Gyan Doshi
2025-02-10 14:32 ` Gyan Doshi
0 siblings, 1 reply; 2+ messages in thread
From: Gyan Doshi @ 2025-02-10 12:23 UTC (permalink / raw)
To: ffmpeg-devel
4b77a0a681 added a new consumer of ff_scale_adjust_dimensions
which was recently modified to allow for square pixel output.
This commit extends the new option to vpp_amf, and unbreaks the building
of vf_amf_common.c
---
doc/filters.texi | 3 +++
libavfilter/vf_amf_common.c | 10 ++++++++--
libavfilter/vf_amf_common.h | 1 +
libavfilter/vf_vpp_amf.c | 1 +
4 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index d72b0da7f3..4cefef6cbc 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25796,6 +25796,9 @@ pixel format is used.
@item force_divisible_by
Work the same as the identical @ref{scale} filter options.
+@item reset_sar
+Works the same as the identical @ref{scale} filter option.
+
@anchor{color_profile}
@item color_profile
Specify all color properties at once.
diff --git a/libavfilter/vf_amf_common.c b/libavfilter/vf_amf_common.c
index 9c48b4218e..cbc532f822 100644
--- a/libavfilter/vf_amf_common.c
+++ b/libavfilter/vf_amf_common.c
@@ -158,7 +158,9 @@ int amf_filter_filter_frame(AVFilterLink *inlink, AVFrame *in)
goto fail;
}
- if (inlink->sample_aspect_ratio.num) {
+ if (ctx->reset_sar)
+ outlink->sample_aspect_ratio = (AVRational){1, 1};
+ else if (inlink->sample_aspect_ratio.num) {
outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
} else
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
@@ -274,6 +276,7 @@ int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format)
enum AVPixelFormat out_sw_format = ctx->format;
FilterLink *inl = ff_filter_link(inlink);
FilterLink *outl = ff_filter_link(outlink);
+ double w_adj = 1.0;
if ((err = ff_scale_eval_dimensions(avctx,
ctx->w_expr, ctx->h_expr,
@@ -281,8 +284,11 @@ int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format)
&ctx->width, &ctx->height)) < 0)
return err;
+ if (ctx->reset_sar)
+ w_adj = inlink->sample_aspect_ratio.num ? (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1.0;
+
ff_scale_adjust_dimensions(inlink, &ctx->width, &ctx->height,
- ctx->force_original_aspect_ratio, ctx->force_divisible_by);
+ ctx->force_original_aspect_ratio, ctx->force_divisible_by, w_adj);
av_buffer_unref(&ctx->amf_device_ref);
av_buffer_unref(&ctx->hwframes_in_ref);
diff --git a/libavfilter/vf_amf_common.h b/libavfilter/vf_amf_common.h
index c4b5ba659a..d0a0214978 100644
--- a/libavfilter/vf_amf_common.h
+++ b/libavfilter/vf_amf_common.h
@@ -48,6 +48,7 @@ typedef struct AMFFilterContext {
char *format_str;
int force_original_aspect_ratio;
int force_divisible_by;
+ int reset_sar;
AMFComponent *component;
AVBufferRef *amf_device_ref;
diff --git a/libavfilter/vf_vpp_amf.c b/libavfilter/vf_vpp_amf.c
index 87bd68074f..92923a4757 100644
--- a/libavfilter/vf_vpp_amf.c
+++ b/libavfilter/vf_vpp_amf.c
@@ -221,6 +221,7 @@ static const AVOption vpp_amf_options[] = {
{ "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, "force_oar" },
{ "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, "force_oar" },
{ "force_divisible_by", "enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1}, 1, 256, FLAGS },
+ { "reset_sar", "reset SAR to 1 and scale to square pixels if scaling proportionally", OFFSET(reset_sar), AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1, FLAGS },
{ NULL },
};
--
2.46.1
_______________________________________________
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] avfilter/vpp_amf: add option reset_sar
2025-02-10 12:23 [FFmpeg-devel] [PATCH] avfilter/vpp_amf: add option reset_sar Gyan Doshi
@ 2025-02-10 14:32 ` Gyan Doshi
0 siblings, 0 replies; 2+ messages in thread
From: Gyan Doshi @ 2025-02-10 14:32 UTC (permalink / raw)
To: ffmpeg-devel
On 2025-02-10 05:53 pm, Gyan Doshi wrote:
> 4b77a0a681 added a new consumer of ff_scale_adjust_dimensions
> which was recently modified to allow for square pixel output.
>
> This commit extends the new option to vpp_amf, and unbreaks the building
> of vf_amf_common.c
Pushed as 7ee4936e0a61ad81c40d7a1afad9a850820213c6
with the outlink SAR assignment shifted as Timo suggested.
Regards,
Gyan
> ---
> doc/filters.texi | 3 +++
> libavfilter/vf_amf_common.c | 10 ++++++++--
> libavfilter/vf_amf_common.h | 1 +
> libavfilter/vf_vpp_amf.c | 1 +
> 4 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index d72b0da7f3..4cefef6cbc 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -25796,6 +25796,9 @@ pixel format is used.
> @item force_divisible_by
> Work the same as the identical @ref{scale} filter options.
>
> +@item reset_sar
> +Works the same as the identical @ref{scale} filter option.
> +
> @anchor{color_profile}
> @item color_profile
> Specify all color properties at once.
> diff --git a/libavfilter/vf_amf_common.c b/libavfilter/vf_amf_common.c
> index 9c48b4218e..cbc532f822 100644
> --- a/libavfilter/vf_amf_common.c
> +++ b/libavfilter/vf_amf_common.c
> @@ -158,7 +158,9 @@ int amf_filter_filter_frame(AVFilterLink *inlink, AVFrame *in)
> goto fail;
> }
>
> - if (inlink->sample_aspect_ratio.num) {
> + if (ctx->reset_sar)
> + outlink->sample_aspect_ratio = (AVRational){1, 1};
> + else if (inlink->sample_aspect_ratio.num) {
> outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
> } else
> outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
> @@ -274,6 +276,7 @@ int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format)
> enum AVPixelFormat out_sw_format = ctx->format;
> FilterLink *inl = ff_filter_link(inlink);
> FilterLink *outl = ff_filter_link(outlink);
> + double w_adj = 1.0;
>
> if ((err = ff_scale_eval_dimensions(avctx,
> ctx->w_expr, ctx->h_expr,
> @@ -281,8 +284,11 @@ int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format)
> &ctx->width, &ctx->height)) < 0)
> return err;
>
> + if (ctx->reset_sar)
> + w_adj = inlink->sample_aspect_ratio.num ? (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1.0;
> +
> ff_scale_adjust_dimensions(inlink, &ctx->width, &ctx->height,
> - ctx->force_original_aspect_ratio, ctx->force_divisible_by);
> + ctx->force_original_aspect_ratio, ctx->force_divisible_by, w_adj);
>
> av_buffer_unref(&ctx->amf_device_ref);
> av_buffer_unref(&ctx->hwframes_in_ref);
> diff --git a/libavfilter/vf_amf_common.h b/libavfilter/vf_amf_common.h
> index c4b5ba659a..d0a0214978 100644
> --- a/libavfilter/vf_amf_common.h
> +++ b/libavfilter/vf_amf_common.h
> @@ -48,6 +48,7 @@ typedef struct AMFFilterContext {
> char *format_str;
> int force_original_aspect_ratio;
> int force_divisible_by;
> + int reset_sar;
>
> AMFComponent *component;
> AVBufferRef *amf_device_ref;
> diff --git a/libavfilter/vf_vpp_amf.c b/libavfilter/vf_vpp_amf.c
> index 87bd68074f..92923a4757 100644
> --- a/libavfilter/vf_vpp_amf.c
> +++ b/libavfilter/vf_vpp_amf.c
> @@ -221,6 +221,7 @@ static const AVOption vpp_amf_options[] = {
> { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, "force_oar" },
> { "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, "force_oar" },
> { "force_divisible_by", "enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1}, 1, 256, FLAGS },
> + { "reset_sar", "reset SAR to 1 and scale to square pixels if scaling proportionally", OFFSET(reset_sar), AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1, FLAGS },
>
> { NULL },
> };
_______________________________________________
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:[~2025-02-10 14:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-10 12:23 [FFmpeg-devel] [PATCH] avfilter/vpp_amf: add option reset_sar Gyan Doshi
2025-02-10 14:32 ` Gyan Doshi
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