Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 1/2] lavfi/libplacebo: apply dovi metadata correctly
Date: Tue,  4 Jan 2022 14:34:35 +0100
Message-ID: <20220104133436.103812-1-ffmpeg@haasn.xyz> (raw)

From: Niklas Haas <git@haasn.dev>

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 <git@haasn.dev>
---
 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 },
-- 
2.34.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".

             reply	other threads:[~2022-01-04 13:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 13:34 Niklas Haas [this message]
2022-01-04 13:34 ` [FFmpeg-devel] [PATCH 2/2] lavfi/showinfo: fix printf precision for dovi metadata Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220104133436.103812-1-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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