Add @mediabunny/dts extension package

This commit is contained in:
Vanilagy
2026-08-15 17:50:47 +02:00
parent 914907b5db
commit e8162f483f
40 changed files with 2142 additions and 31 deletions
+1 -22
View File
@@ -23,17 +23,13 @@ import {
buildAdtsHeaderTemplate,
parseAacAudioSpecificConfig,
} from '../../../shared/aac-misc';
import { DTS_CHANNEL_COUNTS, DTS_SAMPLE_RATES, dtsBitrateFits } from '../../../shared/dts-misc';
const AAC_SAMPLE_RATES
= [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
const OPUS_SAMPLE_RATES = [8000, 12000, 16000, 24000, 48000];
const MP3_SAMPLE_RATES = [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000];
const AC3_SAMPLE_RATES = [32000, 44100, 48000];
const DTS_SAMPLE_RATES = [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000];
/** DTS only has layouts for these channel counts; 3 and 7 have no mapping. */
const DTS_CHANNEL_COUNTS = [1, 2, 4, 5, 6];
const DTS_MAX_FRAME_SIZE = 16384;
const FRAME_SIZE_FALLBACK = 1024; // Just 'cause
@@ -421,20 +417,3 @@ const resolveBitrate = (config: AudioEncoderConfig, codec: AudioCodec) => {
return config.bitrate ?? new Quality('medium')._toAudioBitrate(codec) ?? 0;
};
/**
* The DTS encoder needs each frame to be big enough to hold the per-channel side info and rejects the whole
* configuration when it isn't, so this mirrors the check from FFmpeg's dcaenc.c.
*/
const dtsBitrateFits = (bitrate: number, sampleRate: number, numberOfChannels: number) => {
if (bitrate < 32000 || bitrate > 3840000) {
return false;
}
const hasLfe = numberOfChannels === 6;
const fullbandChannels = numberOfChannels - (hasLfe ? 1 : 0);
const frameBits = 32 * Math.ceil(Math.ceil(bitrate * 512 / sampleRate) / 32);
const minFrameBits = 132 + (493 + 28 * 32) * fullbandChannels + (hasLfe ? 72 : 0);
return frameBits >= minFrameBits && frameBits <= 8 * DTS_MAX_FRAME_SIZE;
};