mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Support mp4a.67
This commit is contained in:
+21
-4
@@ -2,6 +2,7 @@ import {
|
||||
COLOR_PRIMARIES_MAP,
|
||||
MATRIX_COEFFICIENTS_MAP,
|
||||
TRANSFER_CHARACTERISTICS_MAP,
|
||||
assert,
|
||||
bytesToHexString,
|
||||
isAllowSharedBufferSource,
|
||||
last,
|
||||
@@ -392,10 +393,26 @@ export const buildAudioCodecString = (codec: AudioCodec, numberOfChannels: numbe
|
||||
throw new TypeError(`Unhandled codec '${codec}'.`);
|
||||
};
|
||||
|
||||
export const extractAudioCodecString = (codec: AudioCodec, description: Uint8Array | null) => {
|
||||
export type AacCodecInfo = {
|
||||
isMpeg2: boolean;
|
||||
};
|
||||
|
||||
export const extractAudioCodecString = (trackInfo: {
|
||||
codec: AudioCodec | null;
|
||||
codecDescription: Uint8Array | null;
|
||||
aacCodecInfo: AacCodecInfo | null;
|
||||
}) => {
|
||||
const { codec, codecDescription, aacCodecInfo } = trackInfo;
|
||||
|
||||
if (codec === 'aac') {
|
||||
const audioSpecificConfig = parseAacAudioSpecificConfig(description);
|
||||
return `mp4a.40.${audioSpecificConfig.objectType}`;
|
||||
assert(aacCodecInfo);
|
||||
|
||||
if (aacCodecInfo.isMpeg2) {
|
||||
return 'mp4a.67';
|
||||
} else {
|
||||
const audioSpecificConfig = parseAacAudioSpecificConfig(codecDescription);
|
||||
return `mp4a.40.${audioSpecificConfig.objectType}`;
|
||||
}
|
||||
} else if (codec === 'mp3') {
|
||||
return 'mp3';
|
||||
} else if (codec === 'opus') {
|
||||
@@ -404,7 +421,7 @@ export const extractAudioCodecString = (codec: AudioCodec, description: Uint8Arr
|
||||
return 'vorbis';
|
||||
} else if (codec === 'flac') {
|
||||
return 'flac';
|
||||
} else if (codec.startsWith('pcm-')) {
|
||||
} else if (codec?.startsWith('pcm-')) {
|
||||
return codec;
|
||||
} else if (codec === 'ulaw') {
|
||||
return 'ulaw';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
AacCodecInfo,
|
||||
AudioCodec,
|
||||
Av1CodecInfo,
|
||||
extractAudioCodecString,
|
||||
@@ -67,6 +68,7 @@ type InternalTrack = {
|
||||
sampleRate: number;
|
||||
codec: AudioCodec | null;
|
||||
codecDescription: Uint8Array | null;
|
||||
aacCodecInfo: AacCodecInfo | null;
|
||||
};
|
||||
});
|
||||
|
||||
@@ -647,6 +649,7 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
sampleRate: -1,
|
||||
codec: null,
|
||||
codecDescription: null,
|
||||
aacCodecInfo: null,
|
||||
};
|
||||
}
|
||||
}; break;
|
||||
@@ -972,8 +975,9 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
const payloadStart = this.isobmffReader.pos;
|
||||
|
||||
const objectTypeIndication = this.isobmffReader.readU8();
|
||||
if (objectTypeIndication === 0x40) {
|
||||
if (objectTypeIndication === 0x40 || objectTypeIndication === 0x67) {
|
||||
track.info.codec = 'aac';
|
||||
track.info.aacCodecInfo = { isMpeg2: objectTypeIndication === 0x67 };
|
||||
} else if (objectTypeIndication === 0x69 || objectTypeIndication === 0x6b) {
|
||||
track.info.codec = 'mp3';
|
||||
} else if (objectTypeIndication === 0xdd) {
|
||||
@@ -2179,7 +2183,7 @@ class IsobmffAudioTrackBacking extends IsobmffTrackBacking<EncodedAudioChunk> im
|
||||
|
||||
async getDecoderConfig(): Promise<AudioDecoderConfig> {
|
||||
return {
|
||||
codec: extractAudioCodecString(this.internalTrack.info.codec!, this.internalTrack.info.codecDescription),
|
||||
codec: extractAudioCodecString(this.internalTrack.info),
|
||||
numberOfChannels: this.internalTrack.info.numberOfChannels,
|
||||
sampleRate: this.internalTrack.info.sampleRate,
|
||||
description: this.internalTrack.info.codecDescription ?? undefined,
|
||||
|
||||
Reference in New Issue
Block a user