• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Read and write media metadata using ffmpeg

node-ffmetadata

Read and write media metadata using ffmpeg's metadata framework.

Alternatives

See also #19 for some discussion.

Usage

var ffmetadata = require("ffmetadata");

// Set path to ffmpeg - optional if in $PATH or $FFMPEG_PATH
ffmetadata.setFfmpegPath("/path/to/ffmpeg");

// Read song.mp3 metadata
ffmetadata.read("song.mp3", function(err, data) {
	if (err) console.error("Error reading metadata", err);
	else console.log(data);
});

// Set the artist for song.mp3
var data = {
  artist: "Me",
};
ffmetadata.write("song.mp3", data, function(err) {
	if (err) console.error("Error writing metadata", err);
	else console.log("Data written");
});

Artwork

You can optionally include an array of files to be added to the source file. This is a destructive action, it will overwrite any previous streams on the file. For audio data, this is typically just one image. For video, this is where you would write additional audio streams or subtitle tracks.

var options = {
  attachments: ["cover.jpg"],
};
ffmetadata.write("song.mp3", {}, options, function(err) {
	if (err) console.error("Error writing cover art");
	else console.log("Cover art added");
});

Metadata

Metadata might include the following fields:

  • "artist": artist name
  • "album": album name
  • "title": song title
  • "track": place in the album (e.g. "5/8")
  • "disc": for multidisc albums
  • "label": record label
  • "date": arbitrary, but usually year (e.g. "2002")

See FFmpeg Metadata for details.

API

ffmetadata.read(file, [options], callback)

The callback function is called (callback(err, data)) with an error or an object containing metadata from file.

If options.dryRun is truthy, the ffmpeg process is not actually invoked and instead an array of the arguments that would have been used to invoke ffmpeg is returned synchronously. The callback argument is not used in this case.

options.coverPath: Option to provide a path, where ffmpeg will save cover image. Unfortunately, ffmpeg will always convert resulted image, based on extension in provided coverPath.

ffmetadata.write(file, data, [options], callback)

Write metadata to file and optionally append additional attachments (e.g., artwork image).

The data object should contain metadata fields supported by FFmpeg. See the metadata section above for more information.

The options object may be provided with any of the following fields:

  • options.attachments: An array of files that should be appended as additional streams to the output. This can be used to e.g., attach artwork images; see the artwork section above for more information.

  • options["id3v1"]: If this property is truthy, id3 v1 will also be included. This is useful if compatibility with Windows Explorer is desired.

  • options["id3v2.3"]: If this property is truthy, id3 v2.3 will be used (instead of the default of v2.4). This is useful if compatibility with Windows Explorer is desired (see #8).

  • options.dryRun: If this property is truthy, the ffmpeg process is not actually invoked and instead an array of the arguments that would have been used to invoke ffmpeg is returned synchronously. The callback argument is not used in this case.

callback(err) is called when finished, with an error if one occurred.

Path to FFmpeg

By default, the module looks for the ffmpeg executable either in the FFMPEG_PATH and PATH environmental variables. You may also set this path in the code by calling the ffmetadata.setFfmpegPath("path/to/ffmpeg") function.

Installation

Dependency: FFmpeg or libav must be installed on the system. This module uses the ffmpeg command-line tool. Version: 0.10.

npm install ffmetadata

More Repositories

1

node-sanitize-filename

Sanitize string for use as filename
JavaScript
337
star
2

node-libs-react-native

Node core modules for React Native
JavaScript
204
star
3

check-node-version

Check installed versions of node and npm
JavaScript
75
star
4

node-fpcalc

Calculate AcoustID audio fingerprint
JavaScript
68
star
5

css-eliminator

CSS dead code elimination
CSS
43
star
6

vtree-select

Select virtual-dom nodes using css selectors
JavaScript
31
star
7

node-acoustid

Get music metadata from AcoustID web service
JavaScript
28
star
8

node-stream-reduce

Reduce stream data to a single value
JavaScript
20
star
9

js-opc

Open Pixel Control protocol
JavaScript
16
star
10

truncate-utf8-bytes

Truncate string to length in bytes
JavaScript
15
star
11

js-is-integer

ES2015 (ES6) Number.isInteger polyfill
JavaScript
12
star
12

html-linkify

Turn plain text links into safe HTML anchor elements
JavaScript
11
star
13

html-escape

Escape string to be safe for use in html
JavaScript
7
star
14

nextcaltrain

Find the next Caltrain
JavaScript
7
star
15

music-organizer

Automated music metadata using MusicBrainz data
JavaScript
7
star
16

utf8-byte-length

Get byte length of utf8 string
JavaScript
5
star
17

node-stream-filter

Filter stream data
JavaScript
5
star
18

opc-simulator

Web-based Open Pixel Control simulator
JavaScript
5
star
19

nextcaltrain.com

Caltrain schedule web application
JavaScript
4
star
20

immutable-to-js

Convert immutable-js value to regular js value
JavaScript
4
star
21

spheron-accel

Stream accelerometer data from your Sphero
JavaScript
3
star
22

js-multi-compare

Compose array sort compare functions
JavaScript
3
star
23

window-scroll

Polyfill for window.scrollX and window.scrollY
JavaScript
3
star
24

devbox

Automated development machine configuration
Shell
2
star
25

bunyan-express-serializer

Bunyan serializer for Express objects
JavaScript
2
star
26

search-requires

Find require() calls to a given module
JavaScript
2
star
27

simple-passport

Minimal implementation of the PassportJS interface
JavaScript
2
star
28

boxjump

Multiplayer html5 game
CoffeeScript
2
star
29

js-map-values

Map object values, return a new object
JavaScript
2
star
30

map-stream-limit

Like map-stream but with concurrency limit
JavaScript
2
star
31

http-route

Functional HTTP routing
JavaScript
2
star
32

format-json-log

Human-readable json logs
JavaScript
1
star
33

set-input-value

Set input value and keep cursor position
JavaScript
1
star
34

jQuery-insertAt

Insert content as n-th child of element
JavaScript
1
star
35

data-uri-stream

Transform stream to create a data uri
JavaScript
1
star
36

node-stream-buffer

Buffer a stream and replay data at any time
JavaScript
1
star
37

dotfiles

My personal dotfiles
Shell
1
star
38

parse-binary-stream

Parse n-byte chunks from a binary stream
JavaScript
1
star
39

tote

Real-time networked 3D fighting game using Python and OGRE
Python
1
star
40

pageinfo

Get information (title, images, etc.) about a HTML document
JavaScript
1
star