Give Matroska subtitle cues a BlockDuration (#442)

Subtitle cues were written as SimpleBlocks, which carry no duration. A
SimpleBlock tells the player when a cue starts but not how long to show it,
so players such as VLC and libass-based renderers display nothing for
S_TEXT/WEBVTT tracks muxed into Matroska/WebM.

Route a subtitle chunk that has a positive duration through a BlockGroup so
its BlockDuration is written, matching how additions are already handled.
Non-subtitle tracks and zero-duration cues keep using SimpleBlocks.

Co-authored-by: hikari <[email protected]>
This commit is contained in:
Nicolas
2026-07-18 15:48:55 +02:00
committed by GitHub
co-authored by hikari
parent 454476ab26
commit bf592a87ca
+6 -1
View File
@@ -1168,7 +1168,12 @@ export class MatroskaMuxer extends Muxer {
const msDuration = Math.round(1000 * chunk.duration);
if (!chunk.additions) {
// Subtitle cues need an explicit BlockDuration (a SimpleBlock has none), otherwise players
// like VLC/libass don't know how long to show the cue and render nothing. So a subtitle with
// a duration must go into a BlockGroup even when it has no additions.
const needsBlockGroup = !!chunk.additions || (trackData.type === 'subtitle' && msDuration > 0);
if (!needsBlockGroup) {
// No additions, we can write out a SimpleBlock
view.setUint8(3, Number(chunk.type === 'key') << 7); // Flags (keyframe flag only present for SimpleBlock)