Metadata parser for audio and video media files. Supports file and stream inputs in Node.js and browser environments, extracting format, tag, and duration infor
Metadata parser for audio and video media files. Supports file and stream inputs in Node.js and browser environments, extracting format, tag, and duration infor
Key features:
The music-metadata module is ideal for developers working on media applications, music players, or any project that requires access to detailed audio file metadata.
Module: version 8 migrated from CommonJS to pure ECMAScript Module (ESM). The distributed JavaScript codebase is compliant with the ECMAScript 2020 (11th Edition) standard.
[!NOTE] See also CommonJS backward Compatibility
This module requires a Node.js ≥ 18 engine. It can also be used in a browser environment when bundled with a module bundler.
If you find this project useful and would like to support its development, consider sponsoring or contributing:
Buy me a coffee:
| Audio format | Description | Logo |
|---|---|---|
| AIFF / AIFF-C | Audio Interchange File Format | |
| AAC | ADTS / Advanced Audio Coding | |
| APE | Monkey's Audio | |
| ASF | Advanced Systems Format | |
| BWF | Extended WAV format for broadcast and archiving | |
| DSDIFF | Philips DSDIFF | |
| DSF | Sony's DSD Stream File | |
| FLAC | Free Lossless Audio Codec | |
| MP2 | MPEG-1 Audio Layer II (predecessor to MP3) | |
| Matroska | Matroska (EBML), mka, mkv | |
| MP3 | MPEG-1 / MPEG-2 Audio Layer III | |
| MPC | Musepack SV7 | |
| MPEG 4 | mp4, m4a, m4v | |
| Ogg | Open container format | |
| Opus | Low-latency, high-quality codec for speech and music | |
| Speex | Open-source speech codec optimized for VoIP | |
| Theora | Open video compression format (typically paired with Ogg) | |
| Vorbis | Vorbis audio compression | |
| WAV | Uncompressed PCM audio in RIFF container | |
| WebM | WebM | |
| WV | WavPack | |
| WMA | Windows Media Audio |
Following tag header formats are supported:
Following lyric formats are supported:
Support for MusicBrainz tags as written by Picard. ReplayGain tags are supported.
Support for encoding / format details:
Install using npm:
npm install music-metadataor using yarn:
yarn add music-metadataNode.js specific functions to read an audio file or stream:
Cross-platform functions available to read an audio file or stream:
There are multiple ways to parse (read) audio tracks:
ITokenizer to parse using the parseFromTokenizer function.[!NOTE] Direct file access in Node.js is generally faster because it can 'jump' to various parts of the file without reading intermediate data.
These functions are tailored for Node.js environments and leverage Node.js-specific APIs, making them incompatible with browser-based JavaScript engines.
parseFile functionThe parseFile function is intended for extracting metadata from audio files on the local filesystem in a Node.js environment.
It reads the specified file, parses its audio metadata, and returns a promise that resolves with this information.
parseFile(filePath: string, options?: IOptions): PromisefilePath: string
The path to the media file from which metadata should be extracted. This should be a valid path to an audio file on the local filesystem.
options: IOptions (optional)
An optional configuration object that allows customization of the parsing process. These options can include whether to calculate the file's duration, skip embedded cover art, or other parsing behaviors.
Promise:
A promise that resolves to an IAudioMetadata object containing metadata about the audio file. The metadata includes details such as the file format, codec, duration, bit rate, and any embedded tags like album, artist, or track information.
This function is Node.js-only and relies on Node.js-specific APIs to access the filesystem.
For browser environments, consider using the parseBlob to parse File object objects.
The following example demonstrates how to use the parseFile function to read metadata from an audio file:
import { parseFile } from 'music-metadata';
import { inspect } from 'node:util';
(async () => {
try {
const filePath = 'test/samples/MusicBrainz - Beth Hart - Sinner\'s Prayer [id3v2.3].V2.mp3';
const metadata = await parseFile(filePath);
// Output the parsed metadata to the console in a readable format
console.log(inspect(metadata, { showHidden: false, depth: null }));
} catch (error) {
console.error('Error parsing metadata:', error.message);
}
})();No open issues yet, or sync has not completed.