Fix tkhd issue for Apple ecosystem compatibility (#391)

* fix: ensure at least one track per type is enabled for Apple ecosystem compatibility

* Add ensureOneEnabledTrack() to ISOBMFF muxer

* Add test case

---------

Co-authored-by: Vanilagy <[email protected]>
This commit is contained in:
StringWeaver
2026-06-01 22:55:02 +02:00
committed by GitHub
co-authored by Vanilagy
parent c6c768d93e
commit 96d0d9fb22
3 changed files with 71 additions and 7 deletions
+35
View File
@@ -352,3 +352,38 @@ test('PCM audio, no silence padding with approximate timestamps', async () => {
expect(frameCount).toBe(expectedFrameCount);
});
// https://github.com/Vanilagy/mediabunny/pull/391
test('At least one track is enabled even if all are added disabled', async () => {
const output = new Output({
format: new Mp4OutputFormat(),
target: new BufferTarget(),
});
const meta = { decoderConfig: { codec: 'vp8', codedWidth: 1280, codedHeight: 720 } };
const source1 = new EncodedVideoPacketSource('vp8');
output.addVideoTrack(source1, { disposition: { default: false } });
const source2 = new EncodedVideoPacketSource('vp8');
output.addVideoTrack(source2, { disposition: { default: false } });
await output.start();
await source1.add(new EncodedPacket(new Uint8Array(1024), 'key', 0, 0.1), meta);
await source2.add(new EncodedPacket(new Uint8Array(1024), 'key', 0, 0.1), meta);
await output.finalize();
using input = new Input({
source: new BufferSource(output.target.buffer!),
formats: ALL_FORMATS,
});
const tracks = await input.getVideoTracks();
expect(tracks.length).toBe(2);
// Even though both tracks were added disabled, the muxer forces the first one to be enabled
expect((await tracks[0]!.getDisposition()).default).toBe(true);
expect((await tracks[1]!.getDisposition()).default).toBe(false);
});