1

I have an audio stream, and I want to encode, mux and export it along with my video stream. The video works fine, but I can't make the audio work. Highlighting some parts of my code:

  1. Configure the AudioEncoder
this.encoder.configure({
    bitrate: 192000,
    sampleRate: 44100,
    numberOfChannels: 2,
    codec: 'mp4a.40.2',
    aac: { format: 'adts' },
} as any);
  1. I loop through and encode my mixed, interleaved stream (I assume the encoding works fine as I can encode my whole stream)
this.encoder.encode(
    new AudioData({
        data: mixed,
        format: 'f32',
        numberOfChannels: 2,
        timestamp: this.timestamp,
        sampleRate: 44100,
        numberOfFrames: 1024,
    })
);
  1. Write my chunks to an ArrayBuffer
private convertChunksToUint8Array(chunks: EncodedAudioChunk[]): Uint8Array {
    const size = chunks.reduce((acc, chunk) => acc + chunk.byteLength, 0);
    const buffer = new ArrayBuffer(size);
    const view = new Uint8Array(buffer);
    let offset = 0;
    chunks.forEach((chunk) => {
        chunk.copyTo(view.subarray(offset, offset + chunk.byteLength));
        offset += chunk.byteLength;
    });
    return view;
}
  1. I run an FFmpeg command to mux my audio and video stream, but I ran into numerous issues with the audio.

I suspect some header information is missing. If so, what exactly?

Dániel Barta
  • 1,034
  • 7
  • 13

0 Answers0