Define DTS codec, add muxing and demuxing support across ISOBMFF, Matroska, and MPEG-TS, add DTS encode/decode support to @mediabunny/server

This commit is contained in:
Vanilagy
2026-08-15 16:19:12 +02:00
parent ae66f01566
commit 914907b5db
27 changed files with 1182 additions and 56 deletions
+19
View File
@@ -25,6 +25,7 @@ export const CODEC_TO_CODEC_ID: Partial<Record<MediaCodec, NodeAv.AVCodecID>> =
flac: NodeAv.AV_CODEC_ID_FLAC,
ac3: NodeAv.AV_CODEC_ID_AC3,
eac3: NodeAv.AV_CODEC_ID_EAC3,
dts: NodeAv.AV_CODEC_ID_DTS,
};
let cachedHardwareContext: NodeAv.HardwareContext | null | undefined = undefined;
@@ -267,3 +268,21 @@ export const getChannelLayout = (numChannels: number): NodeAv.ChannelLayout => {
default: return { nbChannels: numChannels, order: NodeAv.AV_CHANNEL_ORDER_UNSPEC, mask: 0n };
}
};
/** FL + FR + SL + SR, which libav has no constant for. */
const QUAD_SIDE_MASK = 0x603n;
/**
* DTS insists on the side-based surround layouts and rejects the back-based ones that {@link getChannelLayout}
* hands out, so it gets its own mapping.
*/
export const getDtsChannelLayout = (numChannels: number): NodeAv.ChannelLayout => {
switch (numChannels) {
case 1: return NodeAv.AV_CHANNEL_LAYOUT_MONO;
case 2: return NodeAv.AV_CHANNEL_LAYOUT_STEREO;
case 4: return { nbChannels: 4, order: NodeAv.AV_CHANNEL_ORDER_NATIVE, mask: QUAD_SIDE_MASK };
case 5: return NodeAv.AV_CHANNEL_LAYOUT_5POINT0;
case 6: return NodeAv.AV_CHANNEL_LAYOUT_5POINT1;
default: return { nbChannels: numChannels, order: NodeAv.AV_CHANNEL_ORDER_UNSPEC, mask: 0n };
}
};