Skip to content

Add color_transform normalize filter#1159

Merged
ddennedy merged 14 commits into
masterfrom
linear_trc
Nov 22, 2025
Merged

Add color_transform normalize filter#1159
ddennedy merged 14 commits into
masterfrom
linear_trc

Conversation

@bmatherly

Copy link
Copy Markdown
Member

This filter can force the color TRC to whatever the consumer requests.

Posting this as a draft for conceptual review. The PR should not be pushed until it is tested with Shotcut.

This commit adds a new normalize filter that is added once by the loader on each clip, and then again by the consumer at the end of all the services. The first instance will set the TRC to be whatever is set by consumer.mlt_color_trc. The second will change the TRC to consumer.color_trc.

Example usage:
melt test.mp4 -consumer sdl2 mlt_color_trc=linear mlt_image_format=rgba64

@bmatherly bmatherly marked this pull request as draft September 29, 2025 03:20
@bmatherly bmatherly requested a review from Copilot September 29, 2025 03:20

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 a new colorspace normalize filter that automatically handles color transfer characteristic (TRC) conversions throughout the MLT pipeline. The filter addresses the need to normalize colorspace between different color TRCs as requested by consumers.

  • Adds a new colorspace filter that converts images to the TRC requested by consumers
  • Integrates the filter into the loader pipeline and consumer processing chain
  • Enhances AVFormat modules to properly set color properties on frames

Reviewed Changes

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

Show a summary per file
File Description
src/modules/core/loader.ini Registers the colorspace filter in the loader pipeline
src/modules/core/filter_colorspace.yml Metadata definition for the new colorspace filter
src/modules/core/filter_colorspace.c Implementation of the colorspace conversion filter
src/modules/core/factory.c Registers the filter and its metadata in the core module
src/modules/core/CMakeLists.txt Adds the filter source file to the build
src/modules/avformat/link_avfilter.c Sets color properties from AVFrame to MLT frame properties
src/modules/avformat/filter_avfilter.c Sets color properties from AVFrame to MLT frame properties
src/modules/avformat/common.h Adds function declaration for color range conversion
src/modules/avformat/common.c Implements color range conversion from AV to MLT
src/framework/mlt_image.h Adds function declaration for default TRC lookup
src/framework/mlt_image.c Implements default TRC lookup based on colorspace
src/framework/mlt_consumer.c Integrates colorspace filter into consumer processing
src/framework/mlt.vers Exports the new default TRC function

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/modules/core/filter_colorspace.yml Outdated
Comment thread src/modules/core/filter_colorspace.c Outdated
Comment thread src/modules/avformat/link_avfilter.c Outdated
Comment thread src/modules/avformat/filter_avfilter.c Outdated
Comment thread src/framework/mlt_image.c Outdated
Comment thread src/framework/mlt_image.c Outdated

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

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


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/modules/core/filter_colorspace.yml Outdated
Comment thread src/modules/core/filter_colorspace.c Outdated

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

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


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/modules/core/filter_colorspace.c Outdated
Comment thread src/modules/core/filter_color_transform.c
Comment thread src/framework/mlt_consumer.c
@bmatherly bmatherly force-pushed the linear_trc branch 2 times, most recently from ba3ab80 to cf69925 Compare November 5, 2025 04:02
@bmatherly bmatherly requested a review from Copilot November 5, 2025 04:03

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

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


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

Comment thread src/modules/core/filter_brightness.c Outdated
Comment thread src/framework/mlt_image.c Outdated
@bmatherly bmatherly marked this pull request as ready for review November 6, 2025 02:46
Comment thread src/framework/chain_normalizers.ini Outdated
Comment thread src/modules/core/filter_colorspace.yml Outdated
Comment thread src/modules/core/filter_color_transform.yml
Comment thread src/modules/core/filter_colorspace.c Outdated
Comment thread src/modules/core/filter_colorspace.c Outdated
Comment thread src/framework/mlt_consumer.c Outdated
@ddennedy

ddennedy commented Nov 14, 2025

Copy link
Copy Markdown
Member

I've been doing a lot of testing of the more advanced scenarios involving movit, HLG and decklink plus a little bit of the others, which are working fine.

  • document mlt_color_trc in consumer.h
  • find more places where get_color and anim_get_color are called (C and C++) to handle frame color_trc
  • Update ten_bit presets

Update: strike changing the ten_bit presets

@ddennedy

Copy link
Copy Markdown
Member

I can do the other calls to get_color() if you have not started and want to work on z_color_transform

@bmatherly

Copy link
Copy Markdown
Member Author

I can do the other calls to get_color() if you have not started and want to work on z_color_transform

That is fine with me. Although, I thought I had converted all the filters - it would be good to fix any that I missed.

I am undecided about whether to convert producers (like the color producer) or just let the new color_transform filter make the conversion. There are multiple layers of logic to determine what TRC should be used. And if we copy/paste that all around the code, it might be frustrating to change later. I'd trust your judgement.

@ddennedy

Copy link
Copy Markdown
Member

I think this is ready now. Please review my changes and we can merge.

This image format is supposed to instruct the producer to provide as
native or closest to source as possible. That can be useful by API but
also Movit uses this because it tries to handle things as much as
possible. This improves the color accuracy of SDR within a BT.2020/HLG
project on Movit.

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

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


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

Comment thread src/framework/mlt_types.c Outdated
Comment thread src/framework/mlt_types.c Outdated
Comment thread src/modules/core/filter_color_transform.yml Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bmatherly

Copy link
Copy Markdown
Member Author

Good to go. Thanks for your help.

@ddennedy ddennedy changed the title Add colorspace normalize filter Add color_transform normalize filter Nov 22, 2025
@ddennedy ddennedy merged commit 685ce60 into master Nov 22, 2025
21 checks passed
@ddennedy ddennedy deleted the linear_trc branch November 22, 2025 20:21
@ddennedy ddennedy added this to the v7.36.0 milestone Nov 22, 2025
@ddennedy ddennedy mentioned this pull request Nov 22, 2025
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