1.4.1 • Published 3 years ago

node-fdkaac v1.4.1

Weekly downloads
59
License
ISC
Repository
github
Last release
3 years ago

node-fdkaac

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 command line frontend (by nu774) based on libfdk-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 12.20.* or newer

Installation

You can install it with npm:

$ npm install --save node-fdkaac

If you have not installed libfdk-aac, fdkaac and ffmpeg 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

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

Run on MacOS with brew

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

Example

Encode from file to file

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

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

[...]

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

[...]

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

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

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

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

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

[...]

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

[...]

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

OptionDescriptionValuesDefault
outputOutput filenamePath
profileTarget 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
bitrateTarget bitrate (for CBR)Numberundefined
bitrate-modeBitrate 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
bandwidthFrequency bandwidth (lowpass cut-off frequency) in Hz. Available on AAC LC only.Numberundefined
afterburnerConfigure afterburner mode. When enabled, quality is increased at the expense of additional computational workload.0 (Off), 1 (On)1
lowdelay-sbrConfigure SBR activity on AAC ELD.-1 (Use ELD SBR auto configuration, 0 (Disable SBR on ELD), 1 (Enable SBR on ELD)0
sbr-ratioControls 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-formatTransport 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-checkAdd CRC protection on ADTS header.Booleanfalse
header-periodStreamMuxConfig/PCE repetition period in the transport layer.Numberundefined
gapless-modeMethod 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-delayWhen specified, count SBR decoder delay in encoder delay.Booleanfalse
ignorelengthIgnore length field of data chunk in input WAV file.Booleanfalse
moov-before-mdatPlace 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.Booleanfalse
rawRegard input as raw PCM.Booleanfalse
raw-channelsSpecify number of channels of raw inputNumber2
raw-rateSpecify sample rate of raw input.Number44100
raw-formatSpecify sample format of raw input (details see nu774/fdkaac).StringS16L
metaMeta data for M4A container.Objectundefined

Meta options

OptionDescriptionValuesDefault
titleSet title tag.Stringundefined
artistSet artist tag.Stringundefined
albumSet album tag.Stringundefined
genreSet genre tag.Stringundefined
dateSet date tag.Stringundefined
composerSet composer tag.Stringundefined
groupingSet grouping tag.Stringundefined
commentSet comment tag.Stringundefined
album-artistSet album artist tag.Stringundefined
trackSet track tag, with or without number of total tracks.Number/Totalundefined
diskSet disk tag, with or without number of total discs.Number/Totalundefined
tempoSet tempo (BPM) tag.Numberundefined
tagSet iTunes predefined tag with explicit fourcc key and value. See iTunesMetadata for known predefined keys.\<fcc>:\<value>undefined
long-tagSet arbitrary tag as iTunes custom metadata. Stored in com.apple.iTunes field.\<fcc>:\<value>undefined

Option description text from fdkaac by nu774. Based on fdkaac commit 4682fe4 from Jan 16, 2017.

1.4.1

3 years ago

1.4.0

4 years ago

1.3.1

5 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.0

8 years ago