
Security News
Socket Releases Free Certified Patches for Nuxt Security Vulnerabilities
Socket releases free Certified Patches for high-severity Nuxt vulnerabilities, including server-side remote code execution through server island props.
@mediabunny/aac-encoder
Advanced tools
Some browsers lack support for AAC encoding in their WebCodecs implementations. This extension package provides a reliable AAC-LC encoder for use with Mediabunny. It is implemented using Mediabunny's custom coder API and uses a fast, size-optimized WASM build of FFmpeg's AAC encoder under the hood.
This package, like the rest of Mediabunny, is enabled by its sponsors and their donations. If you've derived value from this package, please consider leaving a donation! 💘
This library peer-depends on Mediabunny. Install both using npm:
npm install mediabunny @mediabunny/aac-encoder
Alternatively, directly include them using a script tag:
<script src="mediabunny.js"></script>
<script src="mediabunny-aac-encoder.js"></script>
This will expose the global objects Mediabunny and MediabunnyAacEncoder. Use mediabunny-aac-encoder.d.ts to provide types for these globals. You can download the built distribution files from the releases page.
import { registerAacEncoder } from '@mediabunny/aac-encoder';
registerAacEncoder();
That's it - Mediabunny now uses the registered AAC encoder automatically.
If you want to be more correct, check for native browser support first:
import { canEncodeAudio } from 'mediabunny';
import { registerAacEncoder } from '@mediabunny/aac-encoder';
if (!(await canEncodeAudio('aac'))) {
registerAacEncoder();
}
Here, we convert an input file to an MP4 with AAC audio:
import {
Input,
ALL_FORMATS,
BlobSource,
Output,
BufferTarget,
Mp4OutputFormat,
canEncodeAudio,
Conversion,
} from 'mediabunny';
import { registerAacEncoder } from '@mediabunny/aac-encoder';
if (!(await canEncodeAudio('aac'))) {
// Only register the custom encoder if there's no native support
registerAacEncoder();
}
const input = new Input({
source: new BlobSource(file), // From a file picker, for example
formats: ALL_FORMATS,
});
const output = new Output({
format: new Mp4OutputFormat(),
target: new BufferTarget(),
});
const conversion = await Conversion.init({
input,
output,
audio: {
codec: 'aac',
},
});
await conversion.execute();
output.target.buffer; // => ArrayBuffer containing the MP4 file
For more ways of using Mediabunny, refer to its guide.
For simplicity, all built WASM artifacts are included in the repo, since these rarely change. However, here are the instructions for building them from scratch:
Install Emscripten and clone FFmpeg. Then, from the Mediabunny root and with Emscripten sourced in:
export FFMPEG_PATH=/path/to/ffmpeg
export MEDIABUNNY_ROOT=$PWD
# Build FFmpeg
cd $FFMPEG_PATH
emmake make distclean
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=emar \
--ranlib=emranlib \
--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
This generates build/aac.js, which contains both the JavaScript "glue code" as well as the compiled WASM inlined.
Then, the complete JavaScript package can be built alongside the rest of Mediabunny by running npm run build in Mediabunny's root.
FAQs
AAC encoder extension for Mediabunny, based on FFmpeg.
The npm package @mediabunny/aac-encoder receives a total of 620,339 weekly downloads. As such, @mediabunny/aac-encoder popularity was classified as popular.
We found that @mediabunny/aac-encoder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket releases free Certified Patches for high-severity Nuxt vulnerabilities, including server-side remote code execution through server island props.

Security News
An open letter signed by 50 companies, from NVIDIA and Microsoft to Mistral and Hugging Face, urges Washington not to restrict open weight AI.

Security News
/Research
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.