mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
feat(codec): add detection support for AC-3, E-AC-3 audio codecs (#275)
* ac3/eac3 detection * fix tests * review pass + follow codebase comments style * Add ac3/eac3 to docs * WIP mpeg-2 * Set registration_descriptor * add support for ac3 system b in mpeg-ts * Update docs with ac3 in .ts support * fix formatting * Remove default to fix linter * Add eac3 to mpeg-ts * fix formatting * Fix failing test * Refactor AC3/EAC3 code a little --------- Co-authored-by: Vanilagy <[email protected]>
This commit is contained in:
@@ -27,6 +27,11 @@ import {
|
||||
FlacBlockType,
|
||||
HevcDecoderConfigurationRecord,
|
||||
Vp9CodecInfo,
|
||||
parseEac3Config,
|
||||
getEac3SampleRate,
|
||||
getEac3ChannelCount,
|
||||
AC3_SAMPLE_RATES,
|
||||
AC3_ACMOD_CHANNEL_COUNTS,
|
||||
} from '../codec-data';
|
||||
import { Demuxer } from '../demuxer';
|
||||
import { Input } from '../input';
|
||||
@@ -952,6 +957,10 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
track.info.codec = 'ulaw';
|
||||
} else if (lowercaseBoxName === 'alaw') {
|
||||
track.info.codec = 'alaw';
|
||||
} else if (lowercaseBoxName === 'ac-3') {
|
||||
track.info.codec = 'ac3';
|
||||
} else if (lowercaseBoxName === 'ec-3') {
|
||||
track.info.codec = 'eac3';
|
||||
} else {
|
||||
console.warn(`Unsupported audio codec (sample entry type '${sampleBoxInfo.name}').`);
|
||||
}
|
||||
@@ -1463,6 +1472,51 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
track.info.codecDescription = description;
|
||||
}; break;
|
||||
|
||||
case 'dac3': { // AC3SpecificBox
|
||||
const track = this.currentTrack;
|
||||
if (!track) {
|
||||
break;
|
||||
}
|
||||
assert(track.info?.type === 'audio');
|
||||
|
||||
const bytes = readBytes(slice, 3);
|
||||
const bitstream = new Bitstream(bytes);
|
||||
|
||||
const fscod = bitstream.readBits(2);
|
||||
bitstream.skipBits(5 + 3); // Skip bsid and bsmod
|
||||
const acmod = bitstream.readBits(3);
|
||||
const lfeon = bitstream.readBits(1);
|
||||
|
||||
if (fscod < 3) {
|
||||
track.info.sampleRate = AC3_SAMPLE_RATES[fscod]!;
|
||||
}
|
||||
|
||||
track.info.numberOfChannels = AC3_ACMOD_CHANNEL_COUNTS[acmod]! + lfeon;
|
||||
}; break;
|
||||
|
||||
case 'dec3': { // EC3SpecificBox
|
||||
const track = this.currentTrack;
|
||||
if (!track) {
|
||||
break;
|
||||
}
|
||||
assert(track.info?.type === 'audio');
|
||||
|
||||
const bytes = readBytes(slice, boxInfo.contentSize);
|
||||
const config = parseEac3Config(bytes);
|
||||
|
||||
if (!config) {
|
||||
console.warn('Invalid dec3 box contents, ignoring.');
|
||||
break;
|
||||
}
|
||||
|
||||
const sampleRate = getEac3SampleRate(config);
|
||||
if (sampleRate !== null) {
|
||||
track.info.sampleRate = sampleRate;
|
||||
}
|
||||
|
||||
track.info.numberOfChannels = getEac3ChannelCount(config);
|
||||
}; break;
|
||||
|
||||
case 'stts': {
|
||||
const track = this.currentTrack;
|
||||
if (!track) {
|
||||
|
||||
Reference in New Issue
Block a user