Add MP3 support to MPEG-TS demuxer

This commit is contained in:
Vanilagy
2026-01-16 10:28:00 +01:00
parent c0f2693cb3
commit e3ee9d91a9
3 changed files with 136 additions and 29 deletions
+38 -1
View File
@@ -483,7 +483,7 @@ test('MPEG-TS transmuxed by FFmpeg', async () => {
expect(audioPacketStats.packetCount).toBe(235);
});
test.only('MPEG-TS with HEVC video', async () => {
test('MPEG-TS with HEVC video', async () => {
using input = new Input({
source: new FilePathSource(path.join(__dirname, '../public/hevc.ts')),
formats: ALL_FORMATS,
@@ -518,3 +518,40 @@ test.only('MPEG-TS with HEVC video', async () => {
expect(packet.duration).toBeCloseTo(0.04166666666);
}
});
test('MPEG-TS with MP3 audio', async () => {
using input = new Input({
source: new FilePathSource(path.join(__dirname, '../public/mp3.ts')),
formats: ALL_FORMATS,
});
const audioTrack = await input.getPrimaryAudioTrack();
assert(audioTrack);
expect(audioTrack.codec).toBe('mp3');
expect(audioTrack.internalCodecId).toBe(0x03);
const audioDecoderConfig = await audioTrack.getDecoderConfig();
expect(audioDecoderConfig).toEqual({
codec: 'mp3',
numberOfChannels: 2,
sampleRate: 48000,
});
const sink = new EncodedPacketSink(audioTrack);
const firstPacket = await sink.getFirstPacket();
assert(firstPacket);
expect(firstPacket.data[0]).toBe(0xff); // MP3 sync byte
expect(firstPacket.type).toBe('key');
expect(firstPacket.duration).toBeGreaterThan(0);
let count = 0;
for await (const packet of sink.packets()) {
expect(packet.data[0]).toBe(0xff);
count++;
}
expect(count).toBeGreaterThan(0);
});