Skip to content

Instantly share code, notes, and snippets.

@wader
Last active January 27, 2025 12:56
Show Gist options
  • Save wader/85fc8e8b7623daa3241313b908f7b509 to your computer and use it in GitHub Desktop.
Save wader/85fc8e8b7623daa3241313b908f7b509 to your computer and use it in GitHub Desktop.
How diff AAC samples using mediainfo

Clone https://github.com/jlesage/docker-mediainfo

Apply patch to make mediainfo dump full AAC samples for --Details=1

diff --git a/src/mediainfo/build.sh b/src/mediainfo/build.sh
index 4183259..2de6c8d 100755
--- a/src/mediainfo/build.sh
+++ b/src/mediainfo/build.sh
@@ -79,6 +79,8 @@ rm -r \
     /tmp/MediaInfoLib/Project/zlib \
     /tmp/MediaInfoLib/Source/ThirdParty/tinyxml2 \

+sed -i 's/Trace_Activated=false/Trace_Activated=true/' /tmp/MediaInfoLib/Source/MediaInfo/Audio/File_Aac_GeneralAudio.cpp
+
 log "Downloading ZenLib package..."
 mkdir /tmp/ZenLib
 curl -# -L -f ${ZENLIB_URL} | tar xz --strip 1 -C /tmp/ZenLib

Build and run:

$ docker build -t mediainfo-dev .
...
$ docker run -v "$PWD:$PWD" -w "$PWD" --entrypoint=mediainfo --rm mediainfo-dev --Details=1 file.mp4
...
40B   raw_data_block (184 bytes)
40B    SCE - single_channel_element (151 bytes)
40B     id_syn_ele:                         0 (0x0) - (3 bits) - SCE - single_channel_element
40B     element_instance_tag:               0 (0x0) - (4 bits)
40B     individual_channel_stream (151 bytes)
40C      global_gain:                       151 (0x97) - (8 bits)
40C      ics_info (2 bytes)
40C       ics_reserved_bit:                 No
40D       window_sequence:                  3 (0x3) - (2 bits) - LONG_STOP_SEQUENCE
40D       window_shape:                     Yes
40D       max_sfb:                          38 (0x26) - (6 bits)
40E       predictor_data_present:           No
40E      section_data (9 bytes)
40E       sect_cb[g][i]:                    11 (0xB) - (4 bits)
40E       sect_len_incr:                    3 (0x03) - (5 bits)
40F       sect_cb[g][i]:                    6 (0x6) - (4 bits)
40F       sect_len_incr:                    5 (0x05) - (5 bits)
410       sect_cb[g][i]:                    11 (0xB) - (4 bits)
...

Diff samples:

$ diff -u \
  <(docker run -v $PWD:$PWD -w $PWD --entrypoint=mediainfo --rm mediainfo-dev --Details=1 a.mp4 | sed -e '1,/Second pass/ d' | cut -b 4-) \
  <(docker run -v $PWD:$PWD -w $PWD --entrypoint=mediainfo --rm mediainfo-dev --Details=1 b.mp4 | sed -e '1,/Second pass/ d' | cut -b 4-)
 --- /dev/fd/11  2025-01-27 13:52:01
+++ /dev/fd/13  2025-01-27 13:52:01
@@ -4,7 +4,7 @@
      id_syn_ele:                         0 (0x0) - (3 bits) - SCE - single_channel_element
      element_instance_tag:               0 (0x0) - (4 bits)
      individual_channel_stream (3 bytes)
-      global_gain:                       160 (0xA0) - (8 bits)
+      global_gain:                       61 (0x3D) - (8 bits)
       ics_info (2 bytes)
        ics_reserved_bit:                 No
        window_sequence:                  1 (0x1) - (2 bits) - LONG_START_SEQUENCE
 ...

Remove sed part to diff container also and you might have to adjust cut if the files are larger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment