From bf592a87caeadcfa56188d5555b2177308b046b5 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sat, 18 Jul 2026 22:48:55 +0900 Subject: [PATCH] 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 --- src/matroska/matroska-muxer.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/matroska/matroska-muxer.ts b/src/matroska/matroska-muxer.ts index 79e2e93..4ce0129 100644 --- a/src/matroska/matroska-muxer.ts +++ b/src/matroska/matroska-muxer.ts @@ -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)