mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-29 03:43:50 +02:00
Add @mediabunny/dts extension package
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user