From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 92D0A4C9D0 for ; Mon, 10 Feb 2025 13:34:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7B68268B05A; Mon, 10 Feb 2025 15:34:50 +0200 (EET) Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA3F668A8B1 for ; Mon, 10 Feb 2025 15:34:44 +0200 (EET) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id F10F7296C1123; Mon, 10 Feb 2025 14:34:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1739194484; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=pQsrn64LOE6n+AaZW+DgsPfPOpCmSldpkWFhM4Et5PY=; b=Lsnswuxuni4ld5O26w3/DcwdZ6O58vibSrMRy70wjDZIdTYEMFYzuCpHBH9OgsrWVU40dB wMHFhXghklzPJNfkc3aubflyPzR7IjXCMx/vjjgsIsSKLCElCUmHB1JMlKpn9enhlgtazN RxJkZtRvKl7QS5TIBjbP5xxEtsO5BWoLSrFHXoY9Lz14f6NesJoP0gNa6HKeF34L4B2+Qw iUWqGOvrB2y3jlupVzAkDE2tVbov1ZyMdbyYXcZ6aWyli9f79Fz4ZKxBmI4oJXN4nIZVmW SqCJxTqhapJVwWSzbkY0rh7kMLcfUATdw+w1+MlSX6grkw3NizfcZmhFTMkm5Q== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Feb 2025 14:34:38 +0100 Message-ID: <20250210133459.1205-1-timo@rothenpieler.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_amf_common: implement reset_sar options X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Timo Rothenpieler Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Implements the new reset_sar option from a28dc06869fe1f98c07e42f9b0a411d2744ff7d7. While at it, this also moves assigning the output sar on the outlink from the filter frame function to config props. --- libavfilter/vf_amf_common.c | 18 ++++++++++++------ libavfilter/vf_amf_common.h | 1 + libavfilter/vf_vpp_amf.c | 5 +++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/libavfilter/vf_amf_common.c b/libavfilter/vf_amf_common.c index fbf364eac1..75339c9f01 100644 --- a/libavfilter/vf_amf_common.c +++ b/libavfilter/vf_amf_common.c @@ -158,11 +158,6 @@ int amf_filter_filter_frame(AVFilterLink *inlink, AVFrame *in) goto fail; } - 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; - av_frame_free(&in); return ff_filter_frame(outlink, out); fail: @@ -274,6 +269,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 +277,11 @@ int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format) &ctx->width, &ctx->height)) < 0) return err; + if (ctx->reset_sar && inlink->sample_aspect_ratio.num) + w_adj = (double)inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den; + ff_scale_adjust_dimensions(inlink, &ctx->width, &ctx->height, - ctx->force_original_aspect_ratio, ctx->force_divisible_by, 1.0); + 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); @@ -343,6 +342,13 @@ int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format) outlink->w = ctx->width; outlink->h = ctx->height; + 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; + hwframes_out->width = outlink->w; hwframes_out->height = outlink->h; 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..2d9df50632 100644 --- a/libavfilter/vf_vpp_amf.c +++ b/libavfilter/vf_vpp_amf.c @@ -216,11 +216,12 @@ static const AVOption vpp_amf_options[] = { { "smpte428", "SMPTE428", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE428 }, 0, 0, FLAGS, "trc" }, { "arib-std-b67", "ARIB_STD_B67", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_COLOR_TRANSFER_CHARACTERISTIC_ARIB_STD_B67 }, 0, 0, FLAGS, "trc" }, - { "force_original_aspect_ratio", "decrease or increase w/h if necessary to keep the original AR", OFFSET(force_original_aspect_ratio), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 2, FLAGS, "force_oar" }, + { "force_original_aspect_ratio", "decrease or increase w/h if necessary to keep the original AR", OFFSET(force_original_aspect_ratio), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, FLAGS, "force_oar" }, { "disable", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 0, FLAGS, "force_oar" }, { "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 }, + { "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.43.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".