[FFmpeg-devel] [PATCH] lavfi/vf_libplacebo: support custom .cube LUTs

Anton Khirnov anton at khirnov.net
Mon Feb 21 13:33:19 EET 2022


Quoting Niklas Haas (2022-02-17 19:03:19)
> From: Niklas Haas <git at haasn.dev>
> 
> Option boilerplate. Very soon we shall definitely need to add some sort
> of generic forward-proof option parsing mechanism to libplacebo..
> ---
>  libavfilter/vf_libplacebo.c | 78 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 78 insertions(+)
> 
> diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> index 31ae28ac38..0ee2db80ed 100644
> --- a/libavfilter/vf_libplacebo.c
> +++ b/libavfilter/vf_libplacebo.c
> @@ -26,6 +26,14 @@
>  #include <libplacebo/utils/libav.h>
>  #include <libplacebo/vulkan.h>
>  
> +struct custom_lut {
> +    const struct pl_custom_lut *lut;
> +    char *path;
> +    void *bin;
> +    int bin_len;
> +    int type;
> +};
> +
>  typedef struct LibplaceboContext {
>      /* lavfi vulkan*/
>      FFVulkanContext vkctx;
> @@ -115,6 +123,11 @@ typedef struct LibplaceboContext {
>      int shader_bin_len;
>      const struct pl_hook *hooks[2];
>      int num_hooks;
> +
> +    /* custom LUTs */
> +    struct custom_lut lut;
> +    struct custom_lut input_lut;
> +    struct custom_lut output_lut;
>  } LibplaceboContext;
>  
>  static inline enum pl_log_level get_log_level(void)
> @@ -202,6 +215,37 @@ static int libplacebo_init(AVFilterContext *avctx)
>      return 0;
>  }
>  
> +static int load_custom_lut(AVFilterContext *avctx, struct custom_lut *lut)
> +{
> +    LibplaceboContext *s = avctx->priv;
> +    uint8_t *buf = NULL;
> +    size_t buf_len;
> +    int err;
> +
> +    if (lut->bin_len) {
> +        // Binary specified
> +        buf = lut->bin;
> +        buf_len = lut->bin_len;
> +    } else if (lut->path) {
> +        // File path specified
> +        if ((err = av_file_map(lut->path, &buf, &buf_len, 0, s)))

Non-overridable IO in random places is evil.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list