Skip to content

Add support for Matroska zlib compressed subtitle tracks #3211

Open
inorichi wants to merge 2 commits into
androidx:mainfrom
inorichi:feature/zlib_text_tracks_in_mkv
Open

Add support for Matroska zlib compressed subtitle tracks #3211
inorichi wants to merge 2 commits into
androidx:mainfrom
inorichi:feature/zlib_text_tracks_in_mkv

Conversation

@inorichi
Copy link
Copy Markdown

@inorichi inorichi commented May 8, 2026

This PR solves #2361

The first commit implements the changes to support zlib compressed subtitles in SUBRIP, ASS, SSA and VTT.
PGS and VOBSUB already support zlib compressed subtitles (I verified this by creating a sample file with zlib compression) so no changes were needed.
The second commit adds the samples and new tests and dumps for those samples.

The implementation looks for the master element ID_CONTENT_COMPRESSION and when present, enables a boolean flag in the current track.

Later, when a subtitle block is processed, a new inflatedSubtitleSample is used to hold the uncompressed data, and follows a similar approach to PgsParser and VobsubParser by using the method Util.maybeInflate and finally copies the result to the real subtitleSample.

The method reset could not be used because the input already contains the codec prefix at the beginning, so I used System.arraycopy after the prefix. Let me know if you prefer another approach.

The samples were created from the existing ones with the closest tool that created them in the first place, so I've used both ffmpeg and mkvmerge. When running diffs on the dumps of the original mkv and derived mkv with zlib compression, the only changes are in the seekMap positions, so I don't think we can reuse other dumps as it's done for other tests, but I'm no expert on the seekMap so let me know if it's possible.

I've also mixed usages of the null terminated samples because zlib data may contain a null byte, so the decompression must be done before looking for a null byte.

The commands used were either of the two:

mkvmerge -o sample_output.mkv --compression 2:zlib sample_input.mkv
ffmpeg -i sample_input.mkv -map 0 -c copy -metadata:s:s:0 compression=zlib sample_output.mkv

@inorichi inorichi force-pushed the feature/zlib_text_tracks_in_mkv branch from 94528b2 to cda36af Compare May 9, 2026 18:44
@tonihei tonihei self-assigned this May 11, 2026
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.

2 participants