mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 05:13:50 +02:00
Add @mediabunny/aac-encoder extension package
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { aacChannelMap, aacFrequencyTable, AudioCodec } from '../codec';
|
||||
import { aacChannelMap, aacFrequencyTable } from '../../shared/aac-misc';
|
||||
import { AudioCodec } from '../codec';
|
||||
import { Demuxer } from '../demuxer';
|
||||
import {
|
||||
ID3_V2_HEADER_SIZE,
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*!
|
||||
* Copyright (c) 2026-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { AacAudioSpecificConfig } from '../codec';
|
||||
import { Bitstream } from '../misc';
|
||||
|
||||
export type AdtsHeaderTemplate = {
|
||||
header: Uint8Array;
|
||||
bitstream: Bitstream;
|
||||
};
|
||||
|
||||
export const buildAdtsHeaderTemplate = (config: AacAudioSpecificConfig): AdtsHeaderTemplate => {
|
||||
const header = new Uint8Array(7);
|
||||
const bitstream = new Bitstream(header);
|
||||
|
||||
const { objectType, frequencyIndex, channelConfiguration } = config;
|
||||
const profile = objectType - 1;
|
||||
|
||||
bitstream.writeBits(12, 0b1111_11111111); // Syncword
|
||||
bitstream.writeBits(1, 0); // MPEG Version
|
||||
bitstream.writeBits(2, 0); // Layer
|
||||
bitstream.writeBits(1, 1); // Protection absence
|
||||
bitstream.writeBits(2, profile); // Profile
|
||||
bitstream.writeBits(4, frequencyIndex); // MPEG-4 Sampling Frequency Index
|
||||
bitstream.writeBits(1, 0); // Private bit
|
||||
bitstream.writeBits(3, channelConfiguration); // MPEG-4 Channel Configuration
|
||||
bitstream.writeBits(1, 0); // Originality
|
||||
bitstream.writeBits(1, 0); // Home
|
||||
bitstream.writeBits(1, 0); // Copyright ID bit
|
||||
bitstream.writeBits(1, 0); // Copyright ID start
|
||||
bitstream.skipBits(13); // Frame length (to be filled per packet)
|
||||
bitstream.writeBits(11, 0x7ff); // Buffer fullness
|
||||
bitstream.writeBits(2, 0); // Number of AAC frames minus 1
|
||||
// Omit CRC check
|
||||
|
||||
return { header, bitstream };
|
||||
};
|
||||
|
||||
export const writeAdtsFrameLength = (bitstream: Bitstream, frameLength: number) => {
|
||||
bitstream.pos = 30;
|
||||
bitstream.writeBits(13, frameLength);
|
||||
};
|
||||
@@ -6,16 +6,17 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { parseAacAudioSpecificConfig, validateAudioChunkMetadata } from '../codec';
|
||||
import { buildAdtsHeaderTemplate, parseAacAudioSpecificConfig, writeAdtsFrameLength } from '../../shared/aac-misc';
|
||||
import { Bitstream } from '../../shared/bitstream';
|
||||
import { validateAudioChunkMetadata } from '../codec';
|
||||
import { Id3V2Writer } from '../id3';
|
||||
import { metadataTagsAreEmpty } from '../metadata';
|
||||
import { assert, Bitstream, toUint8Array } from '../misc';
|
||||
import { assert, toUint8Array } from '../misc';
|
||||
import { Muxer } from '../muxer';
|
||||
import { Output, OutputAudioTrack } from '../output';
|
||||
import { AdtsOutputFormat } from '../output-format';
|
||||
import { EncodedPacket } from '../packet';
|
||||
import { Writer } from '../writer';
|
||||
import { buildAdtsHeaderTemplate, writeAdtsFrameLength } from './adts-misc';
|
||||
|
||||
export class AdtsMuxer extends Muxer {
|
||||
private format: AdtsOutputFormat;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { Bitstream } from '../misc';
|
||||
import { Bitstream } from '../../shared/bitstream';
|
||||
import { FileSlice, readBytes } from '../reader';
|
||||
|
||||
export const MIN_ADTS_FRAME_HEADER_SIZE = 7;
|
||||
|
||||
Reference in New Issue
Block a user