audiomp4quicktimeaudio-processing

Modify ALAC channel configuration inside M4V (MP4) container


I want to modify channel configuration of an ALAC audio stream inside MP4-container without multiplexing the container.

So I need to change letter H of Audio Data Transport Stream with a hex editor for all audio frames. https://wiki.multimedia.cx/index.php/ADTS#Header

I installed AAC Audio ED Viewer to know where I should look at in my hex editor. Because the viewer can only handle AAC streams and I thought ALAC should look similar:

enter image description here

But when I open my AAC reference stream inside the MP4-container I even cannot find the audio frames in the hex editor I see in the viewer:

enter image description here

I can find many syncwords (0xFFF) inside media data container (mdat). But they don't match those I can see in the viewer.

Attachments:

Can someone tell me what I'm doing wrong here?

Best Felix


Solution

  • You have two separate audio tracks (English and German) so you have to edit both trak entries.

    In your hex editor, repeat for both soun atoms...

    1) Search for start position of text soun.
    2) Skip ahead by 101 bytes, should land on start of stsd (for a/v samples descriptions or config).
    3) From start position of text stsd skip ahead 69 bytes...
    4) The next (or 70th) byte should be an 08 and is your 8 channels for the audio channel config.
    5) Change that number (is one byte only) and then check in a mediaplayer or MediaInfoOnline.

    The structure of an STSD atom with ALAC audio config is as follows:
    (via studying FFmpeg source code)

    From STSD atom name's position skip ahead 48 bytes to reach the fun parts:
    (eg: testing from offset 14985 in your example file)

    SIZE    TYPE                    BYTES           MEANING
    -----------------------------------------------------------------------------------------------------------------------
    32bit   atom size               00 00 00 24     36 (length of this atom)
    32bit   tag                     61 6C 61 63     "alac"
    32bit   tag version             00 00 00 00     is always Zero??? (seems so in most files)
    32bit   samples per frame       00 00 10 00     4096 (global value used if channel num is not set inside audio frames)
     8bit   compatible version      00              is 0
     8bit   sample size             18              is 24
     8bit   history mult            28              usually 40
     8bit   initial history         0A              usually 10
     8bit   rice param limit        0E              is 14
     8bit   channels                08              CHANGE THIS FOR A NEW CHANNEL COUNT
    16bit   maxRun                  00 00           is 0
    32bit   max coded frame size    00 01 80 04     98308       (0 means unknown)
    32bit   average bitrate         00 8C A0 00     9216000     (0 means unknown)
    32bit   samplerate              00 00 BB 80     48000 hertz (48khz)