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 v2 18/18] avfilter/vf_libplacebo: add an alpha_mode setting
Date: Wed, 23 Jul 2025 15:47:21 +0200
Message-ID: <20250723135626.1390296-19-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20250723135626.1390296-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

Chooses the desired output alpha mode. Note that this depends on
an upstream version of libplacebo new enough to respect the corresponding
AVFrame field in pl_map_avframe_ex.
---
 doc/filters.texi            |  4 ++++
 libavfilter/vf_libplacebo.c | 13 +++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 13ca065f85..d4566cb594 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -16380,6 +16380,10 @@ leading to no change. For any other value, conversion will be performed.
 
 See the @ref{setparams} filter for a list of possible values.
 
+@item alpha_mode
+Choose the desired output alpha mode, when the output format has an alpha
+channel. See the @ref{setparams} filter for a list of possible values.
+
 @item apply_filmgrain
 Apply film grain (e.g. AV1 or H.274) if present in source frames, and strip
 it from the output. Enabled by default.
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 475030c80d..bb73350da5 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -195,6 +195,7 @@ typedef struct LibplaceboContext {
     int color_primaries;
     int color_trc;
     int rotation;
+    int alpha_mode;
     AVDictionary *extra_opts;
 
 #if PL_API_VER >= 351
@@ -920,6 +921,11 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
     if (s->color_primaries >= 0)
         out->color_primaries = s->color_primaries;
 
+    if (outdesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
+        if (s->alpha_mode >= 0)
+            out->alpha_mode = s->alpha_mode;
+    }
+
     /* Strip side data if no longer relevant */
     if (out->width != ref->width || out->height != ref->height)
         changed |= AV_SIDE_DATA_PROP_SIZE_DEPENDENT;
@@ -1475,6 +1481,13 @@ static const AVOption libplacebo_options[] = {
     {"270",                            NULL,  0, AV_OPT_TYPE_CONST, {.i64=PL_ROTATION_270}, .flags = STATIC, .unit = "rotation"},
     {"360",                            NULL,  0, AV_OPT_TYPE_CONST, {.i64=PL_ROTATION_360}, .flags = STATIC, .unit = "rotation"},
 
+    {"alpha_mode", "select alpha moda", OFFSET(alpha_mode), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVALPHA_MODE_NB-1, DYNAMIC, .unit = "alpha_mode"},
+    {"auto", "keep the same alpha mode",  0, AV_OPT_TYPE_CONST, {.i64=-1},                              0, 0, DYNAMIC, .unit = "alpha_mode"},
+    {"unspecified",                      NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_UNSPECIFIED},   0, 0, DYNAMIC, .unit = "alpha_mode"},
+    {"unknown",                          NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_UNSPECIFIED},   0, 0, DYNAMIC, .unit = "alpha_mode"},
+    {"premultiplied",                    NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_PREMULTIPLIED}, 0, 0, DYNAMIC, .unit = "alpha_mode"},
+    {"straight",                         NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_STRAIGHT},      0, 0, DYNAMIC, .unit = "alpha_mode"},
+
     { "upscaler", "Upscaler function", OFFSET(upscaler), AV_OPT_TYPE_STRING, {.str = "spline36"}, .flags = DYNAMIC },
     { "downscaler", "Downscaler function", OFFSET(downscaler), AV_OPT_TYPE_STRING, {.str = "mitchell"}, .flags = DYNAMIC },
     { "frame_mixer", "Frame mixing function", OFFSET(frame_mixer), AV_OPT_TYPE_STRING, {.str = "none"}, .flags = DYNAMIC },
-- 
2.50.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".

  parent reply	other threads:[~2025-07-23 13:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-23 13:47 [FFmpeg-devel] (no subject) Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 01/18] avutil/frame: add AVFrame.alpha_mode Niklas Haas
2025-07-23 16:00   ` Kacper Michajlow
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 02/18] fftools/ffprobe: add support for AVFrame.alpha_mode Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 03/18] avfilter/vf_showinfo: print alpha mode when relevant Niklas Haas
2025-07-23 16:11   ` Kacper Michajlow
2025-07-24 11:19     ` Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 04/18] avcodec/avcodec: add AVCodecContext.alpha_mode Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 05/18] avcodec/encode: enforce alpha mode compatibility at encode time Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 06/18] avcodec/png: set correct alpha mode Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 07/18] avcodec/exr: " Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 08/18] avcodec/libjxl: " Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 09/18] avcodec/libjxlenc: also attach extra channel info Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 10/18] avcodec/jpegxl: parse and signal correct alpha mode Niklas Haas
2025-07-23 16:19   ` Kacper Michajlow
2025-07-24 11:13     ` Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 11/18] avfilter/vf_scale: don't ignore incoming chroma location Niklas Haas
2025-07-24 11:16   ` Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 12/18] fftools/ffmpeg_enc: don't ignore user selected " Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 13/18] fftools/ffmpeg_enc: forward frame alpha mode to encoder Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 14/18] avfilter/vf_premultiply: tag correct alpha mode on result Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 15/18] avfilter/vf_alphamerge: tag correct alpha mode Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 16/18] avfilter/vf_overlay: respect alpha mode tagging by default Niklas Haas
2025-07-23 13:47 ` [FFmpeg-devel] [PATCH v2 17/18] avfilter/vf_setparams: add alpha_mode parameter Niklas Haas
2025-07-23 13:47 ` Niklas Haas [this message]
2025-07-23 14:11 ` [FFmpeg-devel] Again pre-multiplied alpha Nicolas George
2025-07-23 15:18   ` Niklas Haas
2025-07-23 17:02     ` Nicolas George
2025-07-24 11:11       ` Niklas Haas
2025-07-24 14:59         ` Nicolas George
2025-07-24 20:58           ` 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=20250723135626.1390296-19-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