Files
454476ab26 Fix WebVTT-in-MP4 output by starting the aux writer (#441)
* Fix WebVTT-in-MP4 output by starting the aux writer

The ISOBMFF muxer advertises WebVTT as a supported subtitle codec and maps
it to the wvtt sample entry, but IsobmffMuxer.start() never calls
auxWriter.start(). The aux writer builds subtitle sample boxes in memory, so
the first box write for any subtitle track hits its started === false assert
and muxing fails.

Start the aux writer alongside the main writer so WebVTT subtitle tracks can
be written to MP4/MOV.

* Move code around, add simple WebVTT muxing test

---------

Co-authored-by: hikari <[email protected]>
Co-authored-by: Vanilagy <[email protected]>
2026-07-18 13:45:23 +00:00

58 lines
1.1 KiB
TypeScript

import { test } from 'vitest';
import { Output } from '../../src/output.js';
import { MkvOutputFormat, Mp4OutputFormat } from '../../src/output-format.js';
import { BufferTarget } from '../../src/target.js';
import { TextSubtitleSource } from '../../src/media-source.js';
test('ISOBMFF muxing', async () => {
const output = new Output({
format: new Mp4OutputFormat(),
target: new BufferTarget(),
});
const source = new TextSubtitleSource('webvtt');
output.addSubtitleTrack(source);
await output.start();
await source.add(`WEBVTT
00:00.000 --> 00:00.900
Hildy!
00:01.000 --> 00:01.400
How are you?
00:01.500 --> 00:02.900
Tell me, is the lord of the universe in?
`);
await output.finalize();
});
test('Matroska muxing', async () => {
const output = new Output({
format: new MkvOutputFormat(),
target: new BufferTarget(),
});
const source = new TextSubtitleSource('webvtt');
output.addSubtitleTrack(source);
await output.start();
await source.add(`WEBVTT
00:00.000 --> 00:00.900
Hildy!
00:01.000 --> 00:01.400
How are you?
00:01.500 --> 00:02.900
Tell me, is the lord of the universe in?
`);
await output.finalize();
});