# node-fdkaac

> fdkaac/libfdk-aac AAC/M4A encoder for Node.js

Latest version **1.5.0** (published 2025-06-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-fdkaac
pnpm add node-fdkaac
yarn add node-fdkaac
bun add node-fdkaac
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2025-06-08 |
| First published | 2017-04-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.20 |
| Dependencies | 0 |
| Unpacked size | 66.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jan Karres |
| Maintainers | jankarres, devowlio |
| Keywords | aac, m4a, fdkaac, libfdk-aac, Fraunhofer FDK AAC, encoder, audio |

## Links

- npm: https://www.npmjs.com/package/node-fdkaac
- Repository: https://github.com/devowlio/node-fdkaac
- Issues: https://github.com/devowlio/node-fdkaac/issues
- npm.io page: https://npm.io/package/node-fdkaac

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.5.0 (latest) — 2025-06-08
- 1.4.1 — 2021-08-20
- 1.4.0 — 2021-02-23
- 1.3.1 — 2020-02-05
- 1.3.0 — 2018-11-20
- 1.2.0 — 2018-03-31
- 1.1.1 — 2017-12-06
- 1.1.0 — 2017-12-06
- 1.0.5 — 2017-06-25
- 1.0.4 — 2017-04-26
- 1.0.3 — 2017-04-19
- 1.0.2 — 2017-04-18
- 1.0.0 — 2017-04-18

## README

# node-fdkaac

<img align="right" src="https://assets.devowl.io/git/node-fdkaac/logo.png" alt="node-fdkaac logo" height="180" />

Fraunhofer FDK AAC is a high-quality open-source AAC encoder. For all AAC and M4A encoding needs, a Node.js wrapper of the full [fdkaac](https://github.com/nu774/fdkaac) command line frontend (by [nu774](https://github.com/nu774)) based on [libfdk-aac](https://github.com/mstorsjo/fdk-aac) encoder.

The encoder reads linear PCM audio in either WAV, raw PCM or CAF format and encodes it into an M4A or an AAC file.

## Requirements

-   Linux or MacOS (Windows is NOT support by this package)
-   libfdk-aac, fdkaac and ffmpeg installed (instructions see below)
-   node 18.20.\* or newer

## Installation

You can install it with `npm`:

```bash
$ npm install --save node-fdkaac
```

If you have not installed [libfdk-aac](https://github.com/mstorsjo/fdk-aac), [fdkaac](https://github.com/nu774/fdkaac) and [ffmpeg](https://www.ffmpeg.org/) yet, you find a bash script to compile the source code as `install.sh` in this package.

_install.sh requirements:_

-   automake
-   libtool
-   git

### Run on Debian

```bash
$ sudo apt-get install automake libtool git ffmpeg
$ chmod +x install.sh
$ sudo ./install.sh
```

### Run on MacOS with brew

```bash
$ brew install automake libtool git ffmpeg
$ chmod +x install.sh
$ sudo ./install.sh
```

## Example

### Encode from file to file

```node
const Fdkaac = require("node-fdkaac").Fdkaac;

const encoder = new Fdkaac({
    output: "./audio-files/demo.m4a",
    bitrate: 192,
}).setFile("./audio-files/demo.wav");

encoder
    .encode()
    .then(() => {
        // Encoding finished
    })
    .catch((error) => {
        // Something went wrong
    });
```

### Encode from file to buffer

```node
const Fdkaac = require("node-fdkaac").Fdkaac;

const encoder = new Fdkaac({
    output: "buffer",
    bitrate: 192,
}).setFile("./audio-files/demo.wav");

encoder
    .encode()
    .then(() => {
        // Encoding finished
        const buffer = encoder.getBuffer();
    })
    .catch((error) => {
        // Something went wrong
    });
```

### Encode from buffer to file

```node
[...]

const Fdkaac = require("node-fdkaac").Fdkaac;

const encoder = new Fdkaac({
    "output": "./audio-files/demo.m4a",
    "bitrate": 192
}).setBuffer(audioFileBuffer);

encoder.encode()
    .then(() => {
        // Encoding finished
    })
    .catch((error) => {
        // Something went wrong
    });
```

### Encode from buffer to buffer

```node
[...]

const Fdkaac = require("node-fdkaac").Fdkaac;

const encoder = new Fdkaac({
    "output": "buffer",
    "bitrate": 192
}).setBuffer(audioFileBuffer);

encoder.encode()
    .then(() => {
        // Encoding finished
        const buffer = encoder.getBuffer();
    })
    .catch((error) => {
        // Something went wrong
    });
```

### Get status of encoder as object

```node
const Fdkaac = require("node-fdkaac").Fdkaac;

const encoder = new Fdkaac({
    output: "buffer",
    bitrate: 192,
}).setFile("./audio-files/demo.wav");

encoder
    .encode()
    .then(() => {
        // Encoding finished
    })
    .catch((error) => {
        // Something went wrong
    });

const status = encoder.getStatus();
```

### Get status of encoder as EventEmitter

```node
const Fdkaac = require("node-fdkaac").Fdkaac;

const encoder = new Fdkaac({
    output: "buffer",
    bitrate: 192,
}).setFile("./audio-files/demo.wav");

const emitter = encoder.getEmitter();

emitter.on("progress", ([progress, eta]) => {
    // On progress of encoding; in percent and estimated time of arrival as 00:00
});

emitter.on("finish", () => {
    // On finish
});

emitter.on("error", (error) => {
    // On error
});

encoder
    .encode()
    .then(() => {
        // Encoding finished
    })
    .catch((error) => {
        // Something went wrong
    });
```

### Decode from file to file

```node
const Fdkaac = require("node-fdkaac").Fdkaac;

const decoder = new Fdkaac({
    output: "./audio-files/demo.wav",
}).setFile("./audio-files/demo.m4a");

decoder
    .decode()
    .then(() => {
        // Decoding finished
    })
    .catch((error) => {
        // Something went wrong
    });
```

### Decode from file to buffer

```node
const Fdkaac = require("node-fdkaac").Fdkaac;

const decoder = new Lame({
    output: "buffer",
}).setFile("./audio-files/demo.m4a");

decoder
    .decode()
    .then(() => {
        // Decoding finished
        const buffer = decoder.getBuffer();
    })
    .catch((error) => {
        // Something went wrong
    });
```

### Decode from buffer to file

```node
[...]

const Fdkaac = require("node-fdkaac").Fdkaac;

const decoder = new Lame({
    "output": "./audio-files/demo.wav"
}).setBuffer(m4aInputBuffer);

decoder.decode()
    .then(() => {
        // Decoding finished
    })
    .catch((error) => {
        // Something went wrong
    });
```

### Decode from buffer to buffer

```node
[...]

const Fdkaac = require("node-fdkaac").Fdkaac;

const decoder = new Lame({
    "output": "buffer"
}).setBuffer(mp4aInputBuffer);

decoder.decode()
    .then(() => {
        // Decoding finished
        const buffer = decoder.getBuffer();
    })
    .catch((error) => {
        // Something went wrong
    });
```

## All options

| Option            | Description                                                                                                                                                         | Values                                                                                                                      | Default     |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ----------- |
| output            | Output filename                                                                                                                                                     | Path                                                                                                                        |
| profile           | Target profile (MPEG4 audio object type, AOT)                                                                                                                       | `2` (MPEG-4 AAC LC), `5` (MPEG-4 HE-AAC; SBR), `23` (MPEG-4 AAC LD), `29` (MPEG-4 HE-AAC v2; SBR+PS), `39` (MPEG-4 AAC ELD) | `2`         |
| bitrate           | Target bitrate (for CBR)                                                                                                                                            | Number                                                                                                                      | `undefined` |
| bitrate-mode      | Bitrate configuration mode. Available VBR quality value depends on other parameters such as profile, sample rate, or number of channels.                            | `0` (CBR), `1`-`5` (VBR; higher value => higher bitrate)                                                                    | `0`         |
| bandwidth         | Frequency bandwidth (lowpass cut-off frequency) in Hz. Available on AAC LC only.                                                                                    | Number                                                                                                                      | `undefined` |
| afterburner       | Configure afterburner mode. When enabled, quality is increased at the expense of additional computational workload.                                                 | `0` (Off), `1` (On)                                                                                                         | `1`         |
| lowdelay-sbr      | Configure SBR activity on AAC ELD.                                                                                                                                  | `-1` (Use ELD SBR auto configuration, `0` (Disable SBR on ELD), `1` (Enable SBR on ELD)                                     | `0`         |
| sbr-ratio         | Controls activation of downsampled SBR.                                                                                                                             | `0` (Use lib default), `1` (Use downsampled SBR; default for ELD+SBR), `2` (Use dual-rate SBR; default for HE-AAC)          | `0`         |
| transport-format  | Transport format. Tagging and gapless playback is only available on M4A.                                                                                            | `0` (M4A), `1` (ADIF), `2` (ADTS), `6` (LATM MCP=1), `7` (LATM MCP=0), `10` (LOAS/LATM; LATM within LOAS)                   | `0`         |
| adts-crc-check    | Add CRC protection on ADTS header.                                                                                                                                  | Boolean                                                                                                                     | `false`     |
| header-period     | StreamMuxConfig/PCE repetition period in the transport layer.                                                                                                       | Number                                                                                                                      | `undefined` |
| gapless-mode      | Method to declare amount of encoder delay (and padding) in M4A container. These values are mandatory for proper gapless playback on player side.                    | `0` (iTunSMPB), `1` (ISO standard; edts and sgpd), `2` (Both)                                                               | `0`         |
| include-sbr-delay | When specified, count SBR decoder delay in encoder delay.                                                                                                           | Boolean                                                                                                                     | `false`     |
| ignorelength      | Ignore length field of data chunk in input WAV file.                                                                                                                | Boolean                                                                                                                     | `false`     |
| moov-before-mdat  | Place moov box before mdat box in M4A container. This option might be important for some hardware players, that are known to refuse moov box placed after mdat box. | Boolean                                                                                                                     | `false`     |
| raw               | Regard input as raw PCM.                                                                                                                                            | Boolean                                                                                                                     | `false`     |
| raw-channels      | Specify number of channels of raw input                                                                                                                             | Number                                                                                                                      | `2`         |
| raw-rate          | Specify sample rate of raw input.                                                                                                                                   | Number                                                                                                                      | `44100`     |
| raw-format        | Specify sample format of raw input (details see [nu774/fdkaac](https://github.com/nu774/fdkaac/blob/master/README)).                                                | String                                                                                                                      | `S16L`      |
| meta              | Meta data for M4A container.                                                                                                                                        | Object                                                                                                                      | `undefined` |

_Meta options_

| Option       | Description                                                                                                                                                        | Values            | Default     |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------- | ----------- |
| title        | Set title tag.                                                                                                                                                     | String            | `undefined` |
| artist       | Set artist tag.                                                                                                                                                    | String            | `undefined` |
| album        | Set album tag.                                                                                                                                                     | String            | `undefined` |
| genre        | Set genre tag.                                                                                                                                                     | String            | `undefined` |
| date         | Set date tag.                                                                                                                                                      | String            | `undefined` |
| composer     | Set composer tag.                                                                                                                                                  | String            | `undefined` |
| grouping     | Set grouping tag.                                                                                                                                                  | String            | `undefined` |
| comment      | Set comment tag.                                                                                                                                                   | String            | `undefined` |
| album-artist | Set album artist tag.                                                                                                                                              | String            | `undefined` |
| track        | Set track tag, with or without number of total tracks.                                                                                                             | Number[/Total]    | `undefined` |
| disk         | Set disk tag, with or without number of total discs.                                                                                                               | Number[/Total]    | `undefined` |
| tempo        | Set tempo (BPM) tag.                                                                                                                                               | Number            | `undefined` |
| tag          | Set iTunes predefined tag with explicit fourcc key and value. See [iTunesMetadata](https://code.google.com/p/mp4v2/wiki/iTunesMetadata) for known predefined keys. | \<fcc\>:\<value\> | `undefined` |
| long-tag     | Set arbitrary tag as iTunes custom metadata. Stored in com.apple.iTunes field.                                                                                     | \<fcc\>:\<value\> | `undefined` |

Option description text from [fdkaac](https://github.com/nu774/fdkaac) by [nu774](https://github.com/nu774). Based on fdkaac commit [4682fe4](https://github.com/nu774/fdkaac/tree/4682fe4961b92d3872e47d9fd4d9256151d292e7) from Jan 16, 2017.

---
_Source: https://npm.io/package/node-fdkaac · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
