Rebuild aac-encoder 1.65.2 Use a clean directory with Bash, GNU make, tar, Node.js 22+, pnpm 9.7.0 and Emscripten 4.0.21. On Windows, use MSYS2 UCRT64 with the make package and native Windows Node.js and pnpm on PATH. Activate the Emscripten SDK (source /path/to/emsdk/emsdk_env.sh) and check emcc --version before building. Emscripten compiler revision: d6f42310010ddec0753a69bab01a4b33aae255b7 Mediabunny release: v1.65.2 (173f6b70765fa3a6ffc1c82737514416fa559ef5). Download these site files into that directory and verify their SHA-256 hashes. /analysis/v1/mediabunny-1.65.2-source-complete.tar.gz 0aac703055636530596fb3ed9cd6de03e0f212046c326f8cd05fa19db6ffeaa2 /analysis/v1/mediabunny-aac-encoder-1.65.2-build-inputs.tar.gz 8ed6f0829da145887327ae2597a79fd0d80a1d466fc6f9202f6168cf72006f33 /analysis/v1/ffmpeg-60a2818f.tar.gz 50cac4cd224ec15e613b2180e654466a2ee25f86dde77c88228b80cda69f7351 The source archive for ffmpeg is from https://codeload.github.com/FFmpeg/FFmpeg/tar.gz/60a2818f76dcd1fee3155b1791304af104a0fc1b A Windows (MSYS2) build differs from the published WASM in two bytes: a header path separator and the last bit of one double constant. Its encoded AAC packets and decoded PCM are identical. Byte-for-byte reproduction on other hosts has not been verified. # Windows SDK and MSYS2 Bash use different command entry points. ar=emar ranlib=emranlib if [[ -n "${MSYSTEM:-}" ]]; then emconfigure() { "$EMSDK_PYTHON" "$EMSDK/upstream/emscripten/emconfigure.py" "$(cygpath -m /usr/bin/bash.exe)" "$@"; } emmake() { shift; "$EMSDK_PYTHON" "$EMSDK/upstream/emscripten/emmake.py" "$(cygpath -m /usr/bin/make.exe)" "$@"; } export PATH="$(cygpath -u "$EMSDK")/upstream/bin:$PATH" ar=llvm-ar ranlib=llvm-ranlib fi tar -xzf mediabunny-1.65.2-source-complete.tar.gz tar -xzf mediabunny-aac-encoder-1.65.2-build-inputs.tar.gz tar -xzf ffmpeg-60a2818f.tar.gz cd mediabunny-1.65.2 mkdir -p packages/aac-encoder/build export FFMPEG_PATH="$(cd ../FFmpeg-60a2818f76dcd1fee3155b1791304af104a0fc1b && pwd)" export MEDIABUNNY_ROOT=$PWD # Build FFmpeg cd "$FFMPEG_PATH" emconfigure ./configure \ --target-os=none \ --arch=x86_32 \ --enable-cross-compile \ --disable-asm \ --disable-x86asm \ --disable-inline-asm \ --disable-programs \ --disable-doc \ --disable-debug \ --disable-all \ --disable-everything \ --disable-autodetect \ --disable-pthreads \ --disable-runtime-cpudetect \ --enable-avcodec \ --enable-encoder=aac \ --cc="emcc" \ --cxx=em++ \ --ar="$ar" \ --ranlib="$ranlib" \ --extra-cflags="-DNDEBUG -Oz -flto -msimd128" \ --extra-ldflags="-Oz -flto" emmake make # Compile the bridge between JavaScript and FFmpeg's API cd "$MEDIABUNNY_ROOT/packages/aac-encoder" emcc src/bridge.c \ "$FFMPEG_PATH"/libavcodec/libavcodec.a \ "$FFMPEG_PATH"/libavutil/libavutil.a \ -I"$FFMPEG_PATH" \ -s MODULARIZE=1 \ -s EXPORT_ES6=1 \ -s SINGLE_FILE=1 \ -s ALLOW_MEMORY_GROWTH=1 \ -s ENVIRONMENT=web,worker \ -s FILESYSTEM=0 \ -s MALLOC=emmalloc \ -s SUPPORT_LONGJMP=0 \ -s EXPORTED_RUNTIME_METHODS=cwrap,HEAPU8 \ -s EXPORTED_FUNCTIONS=_malloc,_free \ -msimd128 \ -flto \ -Oz \ -o build/aac.js cd ../.. # Install the exact bundler versions from the upstream lockfile in an isolated directory. tools="$(mktemp -d)" printf '{}\n' > "$tools/package.json" pnpm --dir "$tools" add --save-exact esbuild@0.25.1 esbuild-plugin-external-global@1.0.1 tsx@4.19.4 find-cache-dir@5.0.0 node --input-type=module - "$tools" <<'JS' import { symlinkSync } from 'node:fs'; import { resolve } from 'node:path'; const target = resolve(process.argv[2], 'node_modules'); symlinkSync(target, 'node_modules', process.platform === 'win32' ? 'junction' : 'dir'); JS # Select only the core and this extension in the original upstream bundler. node --input-type=module - aacEncoderVariants <<'JS' import { readFileSync, writeFileSync } from 'node:fs'; const keep = new Set(['mediabunnyVariants', process.argv[2]]); const source = readFileSync('scripts/bundle.ts', 'utf8'); const target = source .replace(/^const (\w+Variants) = await createVariants\([\s\S]*?^\);$/gm, (block, name) => keep.has(name) ? block : '') .replace(/^\t\.\.\.(\w+Variants),$/gm, (line, name) => keep.has(name) ? line : ''); writeFileSync('scripts/bundle-audio.ts', target); JS node node_modules/tsx/dist/cli.mjs scripts/bundle-audio.ts The original published bytes are available in https://registry.npmjs.org/@mediabunny/aac-encoder/-/aac-encoder-1.65.2.tgz Package SHA-256: fc08136f72f5551295ca97218b622ee23aa65c81d39e95c81c7f4c5d96277d41 Unmodified minified module SHA-256: f7ef810c56d7f018929ed0954cdb82670bf2ad0bb988e75bc1a2f3d8bc23495f Rewrite the bare imports to load the same core module as the export Worker. node --input-type=module - <<'JS' import { readFileSync, writeFileSync } from 'node:fs'; const source = readFileSync('packages/aac-encoder/dist/bundles/mediabunny-aac-encoder.min.mjs', 'utf8'); const before = 'from"mediabunny"'; if (source.split(before).length - 1 !== 2) throw new Error('Unexpected import count'); writeFileSync('mediabunny-aac-encoder-1.65.2.min.mjs', source.replaceAll(before, 'from"./mediabunny-1.65.2.min.mjs"')); JS Site module SHA-256 before local modifications: f2014e7269ae71d63db0e398ce8382af57dc591be37cd82fe1c006a5a14774ec To use a modified library, edit its extracted source before building. Serve the resulting module at /analysis/v1/audio-export-94ebadd9b56f/mediabunny-aac-encoder-1.65.2.min.mjs in a local copy of the site, with the existing core module beside it. Use a fresh browser context to bypass any cached copy. Run a new audio export.