Skip to content

VSFilter mangled colors - #94

Merged
peerless2012 merged 5 commits into
peerless2012:masterfrom
moi15moi:VSFilter-mangle-color
Nov 9, 2026
Merged

peerless2012 merged 5 commits into
peerless2012:masterfrom
moi15moi:VSFilter-mangle-color

Conversation

@moi15moi

@moi15moi moi15moi commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Fix #93

To test this, I wrote a script that generates one video per color space libass supports (BT.601, BT.709, SMPTE 240M and FCC, each in limited and full range, plus an untagged video).

Without mangling the color, we could see the difference between the video and the ass draw.

With the video ycbcr-matrix-bt601-pc.mkv and the subtitle track "ycbcr matrix: TV.709"
Before
mpv-shot0001

After
mpv-shot0001

Here are the video generated with the script: ycbcr-matrix-videos.tar.gz

Do the mangling as described in libass:
https://github.com/libass/libass/blob/5b44c4d690254a7bd8de2e048fa23820036b671b/libass/ass_types.h#L157-L262

- A missing or unparsable header means TV.601. "None" leaves colors untouched.
- The video's color space comes from its track format.
  When the video doesn't specify its matrix, it's guessed from its size, like Aegisub: BT.709 above 1024x600, BT.601 below.
  A video that doesn't specify its range is limited.
- The colors are mangled once per atlas piece, when the quads are built. The quads are rebuilt when the header or the video's color space changes.

The conversion gives the same result as androidx/media's ASS decoder (androidx/media#2324).
AssColorTest runs the test cases from that PR.
With adaptive streams, the track format from onTracksChanged is the first track of the group, not the variant being played.
So the color space could be guessed from the wrong resolution and colorInfo.

The color space now comes from onVideoInputFormatChanged.
That format is the played variant's, and it carries the colorInfo read from the stream.

The onTracksChanged guess is only used until the decoder gets a format: CUES bakes subtitle bitmaps during extraction,
before the decoder has received any format.
Later onTracksChanged calls (e.g. a subtitle track switch) keep the decoder's format, since onVideoInputFormatChanged won't fire again.
The guess also now uses a selected track instead of track 0.
The Player.Listener and the AnalyticsListener added in init() were never removed.
After release(), the player kept a reference to the handler, which leaked it
and kept it updating its state on player events.
@peerless2012
peerless2012 merged commit b74893e into peerless2012:master Nov 9, 2026
2 of 4 checks passed
@moi15moi
moi15moi deleted the VSFilter-mangle-color branch November 9, 2026 03:05
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.

VSFilter mangled colors

2 participants