Skip to content

Add a LUT parameter to producer_avformat - #1212

Merged
bmatherly merged 3 commits into
masterfrom
avformat_lut
Mar 28, 2026
Merged

bmatherly merged 3 commits into
masterfrom
avformat_lut

Conversation

@bmatherly

Copy link
Copy Markdown
Member

This parameter allows the application to specify a 3d lut file to be applied to the source.

@ddennedy

Copy link
Copy Markdown
Member

Explain the purpose when there is already avfilter and a filtergraph property on the producer.
What happens when using hwaccel?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for applying a 3D LUT to video decoded by the avformat producer by introducing a new lut property that maps to FFmpeg’s lut3d filter.

Changes:

  • Bump producer_avformat metadata version and add a new lut parameter in the YAML service definition.
  • Extend setup_filters() to optionally insert a lut3d filter (with escaped file path) into the video filter chain.
  • Rebuild the video filter graph when the lut property changes, and ensure filter setup is triggered when lut is present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/modules/avformat/producer_avformat.yml Adds the lut parameter to the avformat producer’s public parameter schema and bumps the module version.
src/modules/avformat/producer_avformat.c Implements LUT handling by inserting lut3d into the filter chain and rebuilding filters on property changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/modules/avformat/producer_avformat.c Outdated
Comment thread src/modules/avformat/producer_avformat.c
@bmatherly

Copy link
Copy Markdown
Member Author

Explain the purpose when there is already avfilter and a filtergraph property on the producer.

The filter needs to be added precisely before the linear color conversion as observed here:
https://forum.shotcut.org/t/using-lut-on-nikon-n-log-footage-gives-very-dark-output/50927

If I use the filtergraph property, then we would also have to use that for rotate.

What happens when using hwaccel?

I was hoping you would have advice about that before I dig into it too deep.

Also see here:
mltframework/shotcut#1809

@ddennedy

Copy link
Copy Markdown
Member

Regarding hwaccel, I think it will work; just checking if you tested that. I tried, but just a basic test like this fails:
melt -verbose ~/Videos/my.mp4 lut='MOONRISE KINGDOM I.cube' in=6100

Thread 1 "melt" received signal SIGSEGV, Segmentation fault.
0x00007ffff1cf0942 in setup_video_filters (self=0x5555561e8400) at /home/ddennedy/src/mlt/src/modules/avformat/producer_avformat.c:1285
1285	    AVStream *stream = format->streams[self->video_index];
(gdb) where
#0  0x00007ffff1cf0942 in setup_video_filters (self=0x5555561e8400)
    at /home/ddennedy/src/mlt/src/modules/avformat/producer_avformat.c:1285
#1  0x00007ffff1cf1110 in setup_filters (self=0x5555561e8400)
    at /home/ddennedy/src/mlt/src/modules/avformat/producer_avformat.c:1400
#2  0x00007ffff1cf37fb in property_changed (owner=0x555556293440, self=0x5555561e8400, name=0x5555562a0280 "lut")
    at /home/ddennedy/src/mlt/src/modules/avformat/producer_avformat.c:2095
#3  0x00007ffff7f85586 in mlt_events_fire
    (self=0x555556293440, id=0x7ffff7fad172 "property-changed", event_data=...)
    at /home/ddennedy/src/mlt/src/framework/mlt_events.c:211
#4  0x00007ffff7f9a6ca in fire_property_changed (self=0x555556293440, name=0x5555562a0280 "lut")
    at /home/ddennedy/src/mlt/src/framework/mlt_properties.c:738
#5  0x00007ffff7f9adca in mlt_properties_set
    (self=0x555556293440, name=0x5555562a0280 "lut", value=0x55555627fc50 "/home/ddennedy/net/media/aws/unsorted/videos/stock/LUTs/MOONRISE KINGDOM I.cube") at /home/ddennedy/src/mlt/src/framework/mlt_properties.c:918
#6  0x00007ffff7f9b25e in mlt_properties_parse
    (self=0x555556293440, namevalue=0x7fffffffe0b4 "lut=/home/ddennedy/net/media/aws/unsorted/videos/stock/LUTs/MOONRISE KINGDOM I.cube") at /home/ddennedy/src/mlt/src/framework/mlt_properties.c:1125
#7  0x00007ffff665fb55 in producer_melt_init
    (profile=0x555555f9f4f0, type=mlt_service_producer_type, id=0x55555555d8d7 "melt", argv=0x7fffffffdca0)
    at /home/ddennedy/src/mlt/src/modules/core/producer_melt.c:425
#8  0x00007ffff7fa49eb in mlt_repository_create
    (self=0x5555555649c0, profile=0x555555f9f4f0, type=mlt_service_producer_type, service=0x55555555d8d7 "melt", input=0x7fffffffdca0) at /home/ddennedy/src/mlt/src/framework/mlt_repository.c:332
#9  0x00007ffff7f8653d in mlt_factory_producer
    (profile=0x555555f9f4f0, service=0x55555555d8d7 "melt", resource=0x7fffffffdca0)
    at /home/ddennedy/src/mlt/src/framework/mlt_factory.c:343
#10 0x000055555555ad60 in main (argc=5, argv=0x7fffffffdc98) at /home/ddennedy/src/mlt/src/melt/melt.c:976
(gdb) p format
$1 = (AVFormatContext *) 0x0

I made a change:

diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c
index d836443b..5029924c 100644
--- a/src/modules/avformat/producer_avformat.c
+++ b/src/modules/avformat/producer_avformat.c
@@ -2087,7 +2087,7 @@ static void property_changed(mlt_service owner, producer_avformat self, char *na
                 mlt_service_unlock(MLT_PRODUCER_SERVICE(self->parent));
             }
         } else if (!strcmp("lut", name)) {
-            if (self->video_index != -1) {
+            if (self->video_index != -1 && self->video_format) {
                 mlt_service_lock(MLT_PRODUCER_SERVICE(self->parent));
                 avfilter_graph_free(&self->vfilter_graph);
                 self->vfilter_in = NULL;

And now it works with hwaccel plus preview scaling (hw-scaler) and rotate.

@bmatherly

Copy link
Copy Markdown
Member Author

I made a change:

Thanks. The patch works for me and I applied it.

@bmatherly
bmatherly merged commit a204bf4 into master Mar 28, 2026
25 checks passed
@bmatherly
bmatherly deleted the avformat_lut branch March 28, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants