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: Lynne <dev@lynne.ee>
Subject: Re: [FFmpeg-devel] [PATCH v2 01/13] vf_libplacebo: add support for specifying a LUT for the input
Date: Mon, 14 Jul 2025 00:10:57 +0200
Message-ID: <20250714001057.GB17923@haasn.xyz> (raw)
In-Reply-To: <20250712185128.862167-1-dev@lynne.ee>

On Sun, 13 Jul 2025 03:51:10 +0900 Lynne <dev@lynne.ee> wrote:
> This makes it possible to apply Adobe .cube files to inputs.
> ---
>  doc/filters.texi            | 30 ++++++++++++++++++++++++++++++
>  libavfilter/vf_libplacebo.c | 36 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 66 insertions(+)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index ed2956fe75..13add0ff01 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -16321,6 +16321,36 @@ Render frames with rounded corners. The value, given as a float ranging from
>  square to fully circular. In other words, it gives the radius divided by half
>  the smaller side length. Defaults to @code{0.0}.
>
> +@item lut
> +Specifies a custom LUT (in Adobe .cube format) to apply to the colors
> +as part of color conversion. The exact interpretation depends on the value
> +of @option{lut_type}.
> +
> +@item lut_type
> +Controls the interpretation of color values fed to and from the LUT
> +specified as @option{lut}. Valid values are:
> +
> +@table @samp
> +@item auto
> +Chooses the interpretation of the LUT automatically from tagged
> +metadata, and otherwise falls back to @samp{native}. (Default)
> +
> +@item native
> +Applied to raw image contents in its native RGB colorspace (non-linear
> +light), before conversion to the output color space.
> +
> +@item normalized
> +Applied to the normalized RGB image contents, in linear light, before
> +conversion to the output color space.
> +
> +@item conversion
> +Fully replaces the conversion from the image color space to the output
> +color space. If such a LUT is present, it has the highest priority, and
> +overrides any ICC profiles, as well as options related to tone mapping
> +and output colorimetry (@option{color_primaries}, @option{color_trc}).
> +
> +@end table
> +
>  @item extra_opts
>  Pass extra libplacebo internal configuration options. These can be specified
>  as a list of @var{key}=@var{value} pairs separated by ':'. The following example
> diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> index 475030c80d..cbdbe3e665 100644
> --- a/libavfilter/vf_libplacebo.c
> +++ b/libavfilter/vf_libplacebo.c
> @@ -159,6 +159,7 @@ typedef struct LibplaceboContext {
>      pl_vulkan vulkan;
>      pl_gpu gpu;
>      pl_tex tex[4];
> +    struct pl_custom_lut *lut;
>
>      /* input state */
>      LibplaceboInput *inputs;
> @@ -184,6 +185,8 @@ typedef struct LibplaceboContext {
>      AVExpr *pos_x_pexpr, *pos_y_pexpr, *pos_w_pexpr, *pos_h_pexpr;
>      float pad_crop_ratio;
>      float corner_rounding;
> +    char *lut_filename;
> +    enum pl_lut_type lut_type;
>      int force_original_aspect_ratio;
>      int force_divisible_by;
>      int reset_sar;
> @@ -371,6 +374,26 @@ static int find_scaler(AVFilterContext *avctx,
>      return AVERROR(EINVAL);
>  }
>
> +static int parse_custom_lut(LibplaceboContext *s)
> +{
> +    int ret;
> +    uint8_t *lutbuf;
> +    size_t lutbuf_size;
> +
> +    if ((ret = av_file_map(s->lut_filename, &lutbuf, &lutbuf_size, 0, s)) < 0) {
> +        av_log(s, AV_LOG_ERROR,
> +               "The LUT file '%s' could not be read: %s\n",
> +               s->lut_filename, av_err2str(ret));
> +        return ret;
> +    }
> +
> +    s->lut = pl_lut_parse_cube(s->log, lutbuf, lutbuf_size);
> +    av_file_unmap(lutbuf, lutbuf_size);
> +    if (!s->lut)
> +        return AVERROR(EINVAL);
> +    return 0;
> +}
> +
>  static int update_settings(AVFilterContext *ctx)
>  {
>      int err = 0;
> @@ -729,6 +752,9 @@ static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwct
>          RET(parse_shader(avctx, buf, buf_len));
>      }
>
> +    if (s->lut_filename)
> +        RET(parse_custom_lut(s));
> +
>      /* Initialize inputs */
>      s->inputs = av_calloc(s->nb_inputs, sizeof(*s->inputs));
>      if (!s->inputs)
> @@ -757,6 +783,7 @@ static void libplacebo_uninit(AVFilterContext *avctx)
>          av_freep(&s->inputs);
>      }
>
> +    pl_lut_free(&s->lut);
>  #if PL_API_VER >= 351
>      pl_cache_destroy(&s->cache);
>  #endif
> @@ -1005,6 +1032,8 @@ static bool map_frame(pl_gpu gpu, pl_tex *tex,
>          .tex        = tex,
>          .map_dovi   = s->apply_dovi,
>      ));
> +    out->lut = s->lut;
> +    out->lut_type = s->lut_type;
>
>      if (!s->apply_filmgrain)
>          out->film_grain.type = PL_FILM_GRAIN_NONE;
> @@ -1406,6 +1435,13 @@ static const AVOption libplacebo_options[] = {
>      { "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_COLOR, {.str = "black@0"}, .flags = DYNAMIC },
>      { "corner_rounding", "Corner rounding radius", OFFSET(corner_rounding), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, .flags = DYNAMIC },
> +    { "lut", "Path to custom LUT file to apply", OFFSET(lut_filename), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = STATIC },
> +    { "lut_type", "Application mode of the custom LUT", OFFSET(lut_type), AV_OPT_TYPE_INT, { .i64 = PL_LUT_UNKNOWN }, 0, PL_LUT_CONVERSION, STATIC, .unit = "lut_type" },
> +        { "auto",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_UNKNOWN }, 0, 0, STATIC, .unit = "lut_type" },
> +        { "native", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_NATIVE }, 0, 0, STATIC, .unit = "lut_type" },
> +        { "normalized", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_NORMALIZED }, 0, 0, STATIC, .unit = "lut_type" },
> +        { "conversion", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_CONVERSION }, 0, 0, STATIC, .unit = "lut_type" },
> +
>      { "extra_opts", "Pass extra libplacebo-specific options using a :-separated list of key=value pairs", OFFSET(extra_opts), AV_OPT_TYPE_DICT, .flags = DYNAMIC },
>  #if PL_API_VER >= 351
>      { "shader_cache",  "Set shader cache path", OFFSET(shader_cache), AV_OPT_TYPE_STRING, {.str = NULL}, .flags = STATIC },
> --
> 2.50.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".

Commit LGTM.
_______________________________________________
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-13 22:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-12 18:51 Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 02/13] hwcontext_vulkan: temporarily disable host_image_copy Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 03/13] hwcontext_vulkan: enable uniformBufferStandardLayout Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 04/13] vulkan: add support for 16-bit RGGB Bayer pixfmt Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 05/13] lavc/vulkan/common: sign-ify lengths Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 06/13] lavc: add codec ID and profiles for ProRes RAW Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 07/13] lavc: add a ProRes RAW parser Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 08/13] lavc: add a ProRes RAW decoder Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 09/13] lavc: add a ProRes RAW Vulkan hwaccel Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 10/13] scale_vulkan: refactor shader initialization Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 11/13] scale_vulkan: add support for basic Debayering Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 12/13] lavc/vp9dec: use cbs_vp9 to parse the frame header Lynne
2025-07-13 18:15   ` Andreas Rheinhardt
2025-07-14  5:06     ` Lynne
2025-07-12 18:51 ` [FFmpeg-devel] [PATCH v2 13/13] WIP vp9: add Vulkan VP9 hwaccel Lynne
2025-07-13 22:10 ` Niklas Haas [this message]

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=20250714001057.GB17923@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=dev@lynne.ee \
    --cc=ffmpeg-devel@ffmpeg.org \
    /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