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