Skip to content

Fix zlib-compressed ASS dialogue forwarding from Matroska#85

Open
rubinaboobin3-cell wants to merge 1 commit into
peerless2012:masterfrom
rubinaboobin3-cell:master
Open

Fix zlib-compressed ASS dialogue forwarding from Matroska#85
rubinaboobin3-cell wants to merge 1 commit into
peerless2012:masterfrom
rubinaboobin3-cell:master

Conversation

@rubinaboobin3-cell

Copy link
Copy Markdown

This fixes ASS/SSA subtitle rendering for Matroska files whose ASS dialogue payloads are zlib-compressed.

The previous overlay path forwarded dialogue bytes using:

data = sample.data
offset = lineIndex
length = sample.limit() - lineIndex

That works for plain text ASS payloads, but fails for zlib-compressed payloads. Compressed data may contain embedded NUL bytes, and Media3's subtitle sample limit can represent a truncated text-like slice instead of the full compressed payload. Passing only sample.limit() - lineIndex can therefore send an incomplete compressed stream to libass.

Fix

AssTrackOutput now:

  • detects zlib-looking dialogue payloads at the ASS dialogue offset,
  • copies compressed payloads from the full raw backing buffer,
  • inflates them before forwarding to AssHandler.readTrackDialogue,
  • keeps the previous bounded sample.limit() behavior for normal uncompressed ASS payloads,
  • falls back to the original bytes if inflation fails.

Why

Without this, affected fansub MKVs can show symptoms such as:

  • missing dialogue lines,
  • broken signs/typesetting,
  • raw-looking ASS override fragments appearing on screen,
  • intermittent subtitle lines because compressed events are truncated before libass receives them.

The important detail is that zlib inflation must use the full raw sample backing buffer / actual block payload, not the truncated subtitleSample.limit() slice.

Scope

This change is limited to the Media3 Matroska ASS forwarding path in:

lib_ass_media/src/main/java/io/github/peerless2012/ass/media/text/AssTrackOutput.kt

It does not change renderer selection, overlay behavior, font handling, or normal uncompressed ASS forwarding.

Testing

This was validated downstream in an app using libass-android with a Matroska sample containing zlib-compressed ASS dialogue packets. Before the fix, dialogue and signs were missing or broken. After inflating from the full raw sample buffer, dialogue, signs, and effects rendered correctly.

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.

1 participant