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 ESMTP id 31FE746050 for ; Mon, 1 May 2023 15:03:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BAAD668C0C4; Mon, 1 May 2023 18:03:10 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 17FE568BEC4 for ; Mon, 1 May 2023 18:03:05 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 14B094264E; Mon, 1 May 2023 17:03:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1682953384; bh=8x1GvaNVFPNOgp5NdBjMaxU2qB2+iXJdsSoJs+UsSW8=; h=From:To:Cc:Subject:Date:From; b=aZNFsKgNK0mRcbhqlWmoAdUVKRhRHUOtcu2H8n5zdcDL/byEHyKymXE3A5+Q3oYrQ tV9pEYmGMw6zU3f9NPiAZ8iOqSyvUrZ9gwmawYYpgflsMhhTmCT68RPWYVkfoXdjbX p/Z0LGOQy8ibAc1IspmA4LOrIPY+RQ5ZrDaqrZgo= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 May 2023 17:02:59 +0200 Message-Id: <20230501150301.55718-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avfilter/vf_libplacebo: add fillcolor option 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: Niklas Haas 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: From: Niklas Haas In some circumstances, libplacebo will clear the background as a result of cropping/padding. Currently, this uses the hard-coded default fill color of black. This option makes this behavior configurable. --- doc/filters.texi | 6 ++++++ libavfilter/vf_libplacebo.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 6d2672063c1..35df5c339a7 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16018,6 +16018,12 @@ content with black borders, while a value of @code{1.0} always crops off parts of the content. Intermediate values are possible, leading to a mix of the two approaches. +@item fillcolor +Set the color used to fill the output area not covered by the output image, for +example as a result of @ref{normalize_sar}. For the general syntax of this +option, check the @ref{color syntax,,"Color" section in the ffmpeg-utils +manual,ffmpeg-utils}. Defaults to @code{black}. + @item colorspace @item color_primaries @item color_trc diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 66929223dd9..fcdc97e48e2 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -18,6 +18,7 @@ #include "libavutil/file.h" #include "libavutil/opt.h" +#include "libavutil/parseutils.h" #include "internal.h" #include "vulkan_filter.h" #include "scale_eval.h" @@ -73,6 +74,7 @@ typedef struct LibplaceboContext { /* settings */ char *out_format_string; enum AVPixelFormat out_format; + char *fillcolor; char *w_expr; char *h_expr; AVRational target_sar; @@ -225,6 +227,24 @@ static int find_scaler(AVFilterContext *avctx, return AVERROR(EINVAL); } +static int parse_fillcolor(AVFilterContext *avctx, + struct pl_render_params *params, + const char *color_str) +{ + int err = 0; + uint8_t color_rgba[4]; + + RET(av_parse_color(color_rgba, color_str, -1, avctx)); + params->background_color[0] = (float) color_rgba[0] / UINT8_MAX; + params->background_color[1] = (float) color_rgba[1] / UINT8_MAX; + params->background_color[2] = (float) color_rgba[2] / UINT8_MAX; + params->background_transparency = 1.0f - (float) color_rgba[3] / UINT8_MAX; + return 0; + +fail: + return err; +} + static void libplacebo_uninit(AVFilterContext *avctx); static int libplacebo_init(AVFilterContext *avctx) @@ -469,6 +489,7 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out, AVFrame *in) RET(find_scaler(avctx, ¶ms.upscaler, s->upscaler)); RET(find_scaler(avctx, ¶ms.downscaler, s->downscaler)); + RET(parse_fillcolor(avctx, ¶ms, s->fillcolor)); pl_render_image(s->renderer, &image, &target, ¶ms); pl_unmap_avframe(s->gpu, &image); @@ -703,6 +724,7 @@ static const AVOption libplacebo_options[] = { { "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, STATIC }, { "normalize_sar", "force SAR normalization to 1:1", OFFSET(normalize_sar), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, STATIC }, { "pad_crop_ratio", "ratio between padding and cropping when normalizing SAR (0=pad, 1=crop)", OFFSET(pad_crop_ratio), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, 1.0, DYNAMIC }, + { "fillcolor", "Background fill color", OFFSET(fillcolor), AV_OPT_TYPE_STRING, {.str = "black"}, .flags = DYNAMIC }, {"colorspace", "select colorspace", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_SPC_NB-1, DYNAMIC, "colorspace"}, {"auto", "keep the same colorspace", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, STATIC, "colorspace"}, -- 2.40.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".