From patchwork Tue Jan 4 13:34:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 33058 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp16988365iog; Tue, 4 Jan 2022 05:36:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkk0p1PEJ+MONJgoQg0vBJz4l0ZI6z3Sq2fMBC1UfpC3FkPocRl4fIm7SwjXgmTl1xBwsJ X-Received: by 2002:a50:d710:: with SMTP id t16mr48913219edi.50.1641303417800; Tue, 04 Jan 2022 05:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641303417; cv=none; d=google.com; s=arc-20160816; b=CGrl73ADkFxbDHdfcSGy7PW+XpVjUSAIFaknqkR/Wm8bseO3qLSS/w/otd1c7FWmoc tkrB2JlX/WSuRM8GlA6wXWaswt3uuUuXQZA1Ns2q1CIXXVo5726D1R67tjmnlVGQZd/B a1alasrbBVWu7kZUbR9sSBbYkiXRSYbJOzaw64LU+tR/sDKwGjTG/CpaLPUJHG77kSqS l5Z0II5t/1a+0rwUesZrqOqKGHwMTfyKwEC9Gf1WvqwjUFo1NAiPFIOCBMGXrg4nPI3X 25nzru2zTNvsWyzuyuiOGYRN3nUneh78XMpfRH95TpzZPQtTBV/EBVV+nkNDf0/glt6Q nYIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=2grqZF8zhxcQ/Ceoqm4hYdl4wu5bC+gKfii1+ivhViE=; b=azkJpZgvC6l0Ke+ER19KzJSbPJ20L8xmXjIa3nu3J7h+Nyt1Sz7qCBM9lSoe7ftLwQ nFPpva6lPQXoWfwZcxL079EAnmNG1VnvgLlhk7P67YiroluLRu72QPVr6itPetbOYwbs lSDlV3nwN8L9X2uZnSGI/xaHifKC2t9u6nYv8VoWYHNXJgZVTiDbU+gnHd/hBkONSWLy dsnutVUr7m7Pg+O8SdmRfe3lAqPnXqBvhomELmXStPI4Of7LMZ6pr+AjEWcda+2W/Y3b w5Woixe2jJDTDuRrNBKB3aPcFVAQ3yuuCWyAjFtIFPfsA+VBnuWgDoEUjjjYGdPWdHJ6 NXuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="sYOpa/8n"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b11si18940173edk.229.2022.01.04.05.36.57; Tue, 04 Jan 2022 05:36:57 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="sYOpa/8n"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2085568B281; Tue, 4 Jan 2022 15:36:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1AB43680CB2 for ; Tue, 4 Jan 2022 15:36:49 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 3A313494B7; Tue, 4 Jan 2022 14:36:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1641303408; bh=2FkSMnk1SNmAkzlAvndj1UTO4E4lR2nzAQ0M01i+/SE=; h=From:To:Cc:Subject:Date:From; b=sYOpa/8nwILuYhIBOHcLsBAaiAiSZd7H90c4PWQ39MUMMFeQCNxVOmOkhAjbPNlnz Ri+5hZIxIrvDIZAhX/G7la/PYyqreNEL2crJeJTF1ek2ZR/GeWMmzh9G8zrCH3YlC3 PgDVwz47dsgz03rorRL2xLkH36IdaYjr5FzATZk0= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Tue, 4 Jan 2022 14:34:35 +0100 Message-Id: <20220104133436.103812-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] lavfi/libplacebo: apply dovi metadata correctly 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Yc8xV8Mi1Z+t From: Niklas Haas libplacebo supports dolby vision application, but it requires some help from us to set a sensible default output color space, and also strip the dolby vision metadata from the output frame. Failing to do the latter results in an error inside libplacebo. (It can't encode back into a dolby vision color space) Make this functionality toggleable by the user. Note that we also strip dovi metadata from the output in the apply_dolbyvision=0 case, which is partly out of laziness but also partly justified by the fact that dolby vision metadata will generally no longer make sense after passing through a color space conversion or tone mapping filter. (And in the general case, we don't know what libplacebo is doing internally) Signed-off-by: Niklas Haas --- libavfilter/vf_libplacebo.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 5b1e7b5285..e479d6c935 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -47,6 +47,7 @@ typedef struct LibplaceboContext { int force_divisible_by; int normalize_sar; int apply_filmgrain; + int apply_dovi; int colorspace; int color_range; int color_primaries; @@ -400,6 +401,22 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) out->width = outlink->w; out->height = outlink->h; +#if PL_API_VER >= 191 + /* libplacebo cannot (currently) encode back to Dolby Vision */ + av_frame_remove_side_data(out, AV_FRAME_DATA_DOVI_RPU_BUFFER); + av_frame_remove_side_data(out, AV_FRAME_DATA_DOVI_METADATA); + if (s->apply_dovi && av_frame_get_side_data(in, AV_FRAME_DATA_DOVI_METADATA)) { + /* Output of dovi reshaping is always BT.2020+PQ, so infer the correct + * output colorspace defaults */ + out->colorspace = AVCOL_SPC_BT2020_NCL; + out->color_primaries = AVCOL_PRI_BT2020; + out->color_trc = AVCOL_TRC_SMPTE2084; + } else { + /* Prevent Dolby Vision metadata from getting applied by libplacebo */ + av_frame_remove_side_data(in, AV_FRAME_DATA_DOVI_METADATA); + } +#endif + if (s->colorspace >= 0) out->colorspace = s->colorspace; if (s->color_range >= 0) @@ -559,6 +576,7 @@ static const AVOption libplacebo_options[] = { { "antiringing", "Antiringing strength (for non-EWA filters)", OFFSET(antiringing), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, DYNAMIC }, { "sigmoid", "Enable sigmoid upscaling", OFFSET(sigmoid), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC }, { "apply_filmgrain", "Apply film grain metadata", OFFSET(apply_filmgrain), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC }, + { "apply_dolbyvision", "Apply Dolby Vision metadata", OFFSET(apply_dovi), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC }, { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, { "deband_iterations", "Deband iterations", OFFSET(deband_iterations), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 16, DYNAMIC },