What is ffmpeg-static?
The ffmpeg-static npm package provides a static binary of FFmpeg, which is a powerful multimedia framework used to decode, encode, transcode, mux, demux, stream, filter, and play almost anything that humans and machines have created. This package allows you to use FFmpeg without having to install it separately on your system.
What are ffmpeg-static's main functionalities?
Video Conversion
This feature allows you to convert video files from one format to another. The code sample demonstrates converting an MP4 file to an AVI file using the ffmpeg-static binary.
const ffmpegPath = require('ffmpeg-static');
const { exec } = require('child_process');
exec(`${ffmpegPath} -i input.mp4 output.avi`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(`Stdout: ${stdout}`);
});
Audio Extraction
This feature allows you to extract audio from a video file. The code sample demonstrates extracting audio from an MP4 file and saving it as an MP3 file.
const ffmpegPath = require('ffmpeg-static');
const { exec } = require('child_process');
exec(`${ffmpegPath} -i input.mp4 -q:a 0 -map a output.mp3`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(`Stdout: ${stdout}`);
});
Video Compression
This feature allows you to compress video files to reduce their size. The code sample demonstrates compressing an MP4 file using the H.265 codec.
const ffmpegPath = require('ffmpeg-static');
const { exec } = require('child_process');
exec(`${ffmpegPath} -i input.mp4 -vcodec libx265 -crf 28 output.mp4`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(`Stdout: ${stdout}`);
});
Other packages similar to ffmpeg-static
fluent-ffmpeg
The fluent-ffmpeg package provides a fluent API for working with FFmpeg. It allows you to chain commands and options in a more readable and maintainable way compared to using raw command-line strings. It also handles the installation of FFmpeg for you.
ffmpeg
The ffmpeg package is a simple wrapper around the FFmpeg command-line tool. It allows you to execute FFmpeg commands from within your Node.js application. Unlike ffmpeg-static, it does not provide a static binary, so you need to have FFmpeg installed on your system.
ffmpeg-binaries
The ffmpeg-binaries package provides precompiled FFmpeg binaries for various platforms. It is similar to ffmpeg-static in that it provides a static binary, but it may not be as frequently updated or as widely used.
ffmpeg-static
Static ffmpeg binaries for macOS, Linux, Windows.
Supports macOS (64-bit and arm64), Linux (32 and 64-bit, armhf, arm64), Windows (32 and 64-bit). The ffmpeg version currently used is 6.0
.
Note: The version of ffmpeg-static
follows SemVer. When releasing new versions, we do not consider breaking changes in ffmpeg
itself, but only the JS interface (see below). For example, ffmpeg-static@4.5.0
might download ffmpeg 5.0
. To prevent an ffmpeg-static
upgrade downloading backwards-incompatible ffmpeg versions, use a strict version range for it or use a lockfile.
Also check out node-ffmpeg-installer
!
Installation
$ npm install ffmpeg-static
Note: During installation, it will download the appropriate ffmpeg
binary from the b6.0
GitHub release. Use and distribution of the binary releases of ffmpeg
are covered by their respective license.
Custom binaries url
By default, the ffmpeg
binary will get downloaded from https://github.com/eugeneware/ffmpeg-static/releases/download
. To customise this, e.g. when using a mirror, set the FFMPEG_BINARIES_URL
environment variable.
export FFMPEG_BINARIES_URL=https://cdn.npmmirror.com/binaries/ffmpeg-static
npm install ffmpeg-static
Electron & other cross-platform packaging tools
Because ffmpeg-static
will download a binary specific to the OS/platform, you need to purge node_modules
before (re-)packaging your app for a different OS/platform (read more in #35).
Example Usage
Returns the path of a statically linked ffmpeg binary on the local filesystem.
const pathToFfmpeg = require('ffmpeg-static')
console.log(pathToFfmpeg)
Check the example script for a more thorough example.
Sources of the binaries
The binaries downloaded by ffmpeg-static
are from these locations:
Show your support
This npm package includes statically linked binaries that are produced by the following individuals. Please consider supporting and donating to them who have been providing quality binary builds for many years: