mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Add @mediabunny/aac-encoder extension package
This commit is contained in:
@@ -93,6 +93,7 @@ export default withMermaid({
|
||||
text: 'Extensions',
|
||||
items: [
|
||||
{ text: 'mp3-encoder', link: '/guide/extensions/mp3-encoder' },
|
||||
{ text: 'aac-encoder', link: '/guide/extensions/aac-encoder' },
|
||||
{ text: 'ac3', link: '/guide/extensions/ac3' },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -20,5 +20,6 @@
|
||||
"Miscellaneous": "Whatever's left.",
|
||||
|
||||
"@mediabunny/mp3-encoder": "Adds MP3 encoder support to Mediabunny.",
|
||||
"@mediabunny/ac3": "Adds AC-3/E-AC-3 decoder and encoder support to Mediabunny."
|
||||
"@mediabunny/ac3": "Adds AC-3/E-AC-3 decoder and encoder support to Mediabunny.",
|
||||
"@mediabunny/aac-encoder": "Adds AAC encoder support to Mediabunny."
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
# @mediabunny/aac-encoder
|
||||
|
||||
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](../supported-formats-and-codecs#custom-coders) and uses a fast, size-optimized WASM build of [FFmpeg](https://ffmpeg.org/)'s AAC encoder under the hood.
|
||||
|
||||
<a class="!no-underline inline-flex items-center gap-1.5" :no-icon="true" href="https://github.com/Vanilagy/mediabunny/blob/main/packages/aac-encoder/README.md">
|
||||
GitHub page
|
||||
<span class="vpi-arrow-right" />
|
||||
</a>
|
||||
|
||||
## Installation
|
||||
|
||||
This library peer-depends on Mediabunny. Install both using npm:
|
||||
```bash
|
||||
npm install mediabunny @mediabunny/aac-encoder
|
||||
```
|
||||
|
||||
Alternatively, directly include them using a script tag:
|
||||
```html
|
||||
<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](https://github.com/Vanilagy/mediabunny/releases).
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
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:
|
||||
```ts
|
||||
import { canEncodeAudio } from 'mediabunny';
|
||||
import { registerAacEncoder } from '@mediabunny/aac-encoder';
|
||||
|
||||
if (!(await canEncodeAudio('aac'))) {
|
||||
registerAacEncoder();
|
||||
}
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
Here, we convert an input file to an MP4 with AAC audio:
|
||||
|
||||
```ts
|
||||
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,
|
||||
});
|
||||
await conversion.execute();
|
||||
|
||||
output.target.buffer; // => ArrayBuffer containing the MP4 file
|
||||
```
|
||||
@@ -37,13 +37,13 @@ Mediabunny ships with built-in decoders and encoders for all audio PCM codecs, m
|
||||
|
||||
### Audio codecs
|
||||
|
||||
- `'aac'` - Advanced Audio Coding (AAC)
|
||||
- `'aac'` - Advanced Audio Coding (AAC) [^1]
|
||||
- `'opus'` - Opus
|
||||
- `'mp3'` - MP3
|
||||
- `'mp3'` - MP3 [^2]
|
||||
- `'vorbis'` - Vorbis
|
||||
- `'flac'` - Free Lossless Audio Codec (FLAC)
|
||||
- `'ac3'` - Dolby Digital (AC-3) [^1]
|
||||
- `'eac3'` - Dolby Digital Plus (E-AC-3) [^1]
|
||||
- `'ac3'` - Dolby Digital (AC-3) [^3]
|
||||
- `'eac3'` - Dolby Digital Plus (E-AC-3) [^3]
|
||||
- `'pcm-u8'` - 8-bit unsigned PCM
|
||||
- `'pcm-s8'` - 8-bit signed PCM
|
||||
- `'pcm-s16'` - 16-bit little-endian signed PCM
|
||||
@@ -59,8 +59,6 @@ Mediabunny ships with built-in decoders and encoders for all audio PCM codecs, m
|
||||
- `'ulaw'` - μ-law PCM
|
||||
- `'alaw'` - A-law PCM
|
||||
|
||||
[^1]: AC-3 and E-AC-3 are not natively supported by WebCodecs. To encode or decode these codecs, you can use the [`@mediabunny/ac3`](./extensions/ac3) extension package, or provide your own [custom coder](#custom-coders).
|
||||
|
||||
### Subtitle codecs
|
||||
|
||||
- `'webvtt'` - WebVTT
|
||||
@@ -69,7 +67,7 @@ Mediabunny ships with built-in decoders and encoders for all audio PCM codecs, m
|
||||
|
||||
Not all codecs can be used with all containers. The following table specifies the supported codec-container combinations:
|
||||
|
||||
| | .mp4 | .mov | .mkv | .webm[^2] | .ogg | .mp3 | .wav | .aac | .flac | .ts |
|
||||
| | .mp4 | .mov | .mkv | .webm[^4] | .ogg | .mp3 | .wav | .aac | .flac | .ts |
|
||||
|:--------------:|:--------:|:-----:|:-----:|:---------:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
|
||||
| `'avc'` | ✓ | ✓ | ✓ | | | | | | | ✓ |
|
||||
| `'hevc'` | ✓ | ✓ | ✓ | | | | | | | ✓ |
|
||||
@@ -97,11 +95,13 @@ Not all codecs can be used with all containers. The following table specifies th
|
||||
| `'pcm-f64be'` | ✓ | ✓ | | | | | | | | |
|
||||
| `'ulaw'` | | ✓ | | | | | ✓ | | | |
|
||||
| `'alaw'` | | ✓ | | | | | ✓ | | | |
|
||||
| `'webvtt'`[^3] | (✓) | | (✓) | (✓) | | | | | | |
|
||||
| `'webvtt'`[^5] | (✓) | | (✓) | (✓) | | | | | | |
|
||||
|
||||
|
||||
[^2]: WebM only supports a small subset of the codecs supported by Matroska. However, this library can technically read all codecs from a WebM that are supported by Matroska.
|
||||
[^3]: WebVTT can only be written, not read.
|
||||
[^1]: In some browsers, AAC encoding is not supported by WebCodecs. You can polyfill it with the [`@mediabunny/aac-encoder`](./extensions/aac-encoder) extension package, or provide your own [custom coder](#custom-coders).
|
||||
[^2]: MP3 encoding is not supported by WebCodecs. You can polyfill it with the [`@mediabunny/mp3-encoder`](./extensions/mp3-encoder) extension package, or provide your own [custom coder](#custom-coders).
|
||||
[^3]: AC-3 and E-AC-3 are not natively supported by WebCodecs. To encode or decode these codecs, you can use the [`@mediabunny/ac3`](./extensions/ac3) extension package, or provide your own [custom coder](#custom-coders).
|
||||
[^4]: WebM only supports a small subset of the codecs supported by Matroska. However, this library can technically read all codecs from a WebM that are supported by Matroska.
|
||||
[^5]: WebVTT can only be written, not read.
|
||||
|
||||
## Querying codec encodability
|
||||
|
||||
|
||||
Reference in New Issue
Block a user