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 BDA3D45DD2 for ; Wed, 11 Oct 2023 15:09:43 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 606A468CC12; Wed, 11 Oct 2023 18:09:04 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8BC3768CBBB for ; Wed, 11 Oct 2023 18:08:54 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 4DF654BC33; Wed, 11 Oct 2023 17:08:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1697036934; bh=FvYADoYR/xHO0ApY8ZG3SZl6b9K3yv3jRBL/Z+Lrsf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fw8XKJDfK7cxd2qvYaNxweaD0dAZy1mfkBWxOj/t8dyPBh6VDA2FgQ8Hfrnbqp8La nECJOl7mgteS8gcDJaf95jxFxn5juvS1CZiNd9x7QW0xmEaA2L2g8gWPAhpffNnQZ9 9jN9UOtYEUkAomO3if4aUZbPElwWjtLs921rUc5U= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 Oct 2023 16:55:38 +0200 Message-ID: <20231011150848.117897-5-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011150848.117897-1-ffmpeg@haasn.xyz> References: <20231011150848.117897-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] fftools/ffmpeg_filter: auto-insert zscale filter 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 Since swscale currently can't handle conversion between different colorimetry sets, supplement the missing bits and pieces using zscale. Subject to change in the future, if libswscale ever gets the capability to convert between colorspaces natively. --- fftools/ffmpeg_filter.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index c1bedfda00..c60b9d99f7 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -20,6 +20,8 @@ #include +#include "config_components.h" + #include "ffmpeg.h" #include "libavfilter/avfilter.h" @@ -171,6 +173,9 @@ typedef struct OutputFilterPriv { AVChannelLayout ch_layout; enum AVColorSpace csp; enum AVColorRange color_range; + enum AVChromaLocation chroma_loc; + enum AVColorPrimaries prim; + enum AVColorTransferCharacteristic trc; // time base in which the output is sent to our downstream // does not need to match the filtersink's timebase @@ -188,6 +193,9 @@ typedef struct OutputFilterPriv { const int *sample_rates; const enum AVColorSpace *csps; const enum AVColorRange *color_ranges; + const enum AVChromaLocation *chroma_locs; + const enum AVColorPrimaries *prims; + const enum AVColorTransferCharacteristic *trcs; AVRational enc_timebase; // offset for output timestamps, in AV_TIME_BASE_Q @@ -378,6 +386,17 @@ DEF_CHOOSE_FORMAT(out_color_matrix, enum AVColorSpace, csp, csps, DEF_CHOOSE_FORMAT(out_range, enum AVColorRange, color_range, color_ranges, AVCOL_RANGE_UNSPECIFIED, "%s", av_color_range_name); +#if CONFIG_ZSCALE_FILTER +DEF_CHOOSE_FORMAT(chromal, enum AVChromaLocation, chroma_loc, chroma_locs, + AVCHROMA_LOC_UNSPECIFIED, "%s", av_chroma_location_name); + +DEF_CHOOSE_FORMAT(primaries, enum AVColorPrimaries, prim, prims, + AVCOL_PRI_UNSPECIFIED, "%s", av_color_primaries_name); + +DEF_CHOOSE_FORMAT(transfer, enum AVColorTransferCharacteristic, trc, trcs, + AVCOL_TRC_UNSPECIFIED, "%s", av_color_transfer_name); +#endif + static void choose_channel_layouts(OutputFilterPriv *ofp, AVBPrint *bprint) { if (av_channel_layout_check(&ofp->ch_layout)) { @@ -724,6 +743,21 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) ofp->color_ranges = mjpeg_ranges; } } + if (ost->enc_ctx->chroma_sample_location) { + ofp->chroma_loc = ost->enc_ctx->chroma_sample_location; + } else { + ofp->chroma_locs = c->chroma_locs; + } + if (ost->enc_ctx->color_primaries) { + ofp->prim = ost->enc_ctx->color_primaries; + } else { + ofp->prims = c->primaries; + } + if (ost->enc_ctx->color_trc) { + ofp->trc = ost->enc_ctx->color_trc; + } else { + ofp->trcs = c->trcs; + } if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { ofp->format = ost->enc_ctx->pix_fmt; } else { @@ -1280,6 +1314,34 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, last_filter = filter; pad_idx = 0; } + +#if CONFIG_ZSCALE_FILTER + av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); + choose_chromal(ofp, &bprint); + choose_primaries(ofp, &bprint); + choose_transfer(ofp, &bprint); + if (bprint.len) { + /* Colorspace format conversion needed */ + AVFilterContext *filter; + + if (!av_bprint_is_complete(&bprint)) + return AVERROR(ENOMEM); + + snprintf(name, sizeof(name), "color_out_%d_%d", + ost->file_index, ost->index); + ret = avfilter_graph_create_filter(&filter, + avfilter_get_by_name("zscale"), + name, bprint.str, NULL, fg->graph); + av_bprint_finalize(&bprint, NULL); + if (ret < 0) + return ret; + if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0) + return ret; + + last_filter = filter; + pad_idx = 0; + } +#endif } snprintf(name, sizeof(name), "trim_out_%d_%d", -- 2.42.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".