Install fluent-ffmpeg as a git submodule
masterIf you prefer to manage the dependency manually, you can add it as a git submodule.
$ git submodule add git://github.com/schaermu/node-fluent-ffmpeg.git vendor/fluent-ffmpegrepository·master·Indexed 27 days ago
https://github.com/fluent-ffmpeg/node-fluent-ffmpegA Node.js module providing a fluent API to abstract the FFmpeg command-line interface. It allows developers to configure input/output options, audio and video codecs, filters, and complex filtergraphs. Note: This library is deprecated and no longer maintained.
If you prefer to manage the dependency manually, you can add it as a git submodule.
$ git submodule add git://github.com/schaermu/node-fluent-ffmpeg.git vendor/fluent-ffmpegIf you are contributing API changes (such as new methods), you should update the README and the JSDoc comments in the source code. You can regenerate the JSDoc documentation using the make doc command. It is recommended to commit the regenerated documentation in a single, specific commit to keep the history clean.
$ make docmake test command. It is recommended to have an up-to-date FFmpeg installation to avoid assertion errors caused by missing codecs or bugs.libmp3lame or libx264) are also installed and available to your FFmpeg installation.fluent-ffmpeg requires ffmpeg (>= 0.9) and ffprobe to be installed. You can specify their locations using environment variables or the API.
Environment Variables:
FFMPEG_PATH: Full path to the ffmpeg executable.FFPROBE_PATH: Full path to the ffprobe executable.FLVTOOL2_PATH or FLVMETA_PATH: Path to flvtool2 or flvmeta (required for encoding FLV videos).Windows Users: You must set %FFMPEG_PATH% and %FFPROBE_PATH% as they are typically not in the %PATH%.
API Methods: Use these methods to set paths manually in your code.
You can install the library using npm to add it to your Node.js project.
$ npm install fluent-ffmpegUse output(target[, options]) to add an output file or a writable stream.
Important: Adding an output switches the "current output". Subsequent output-specific methods (like videoCodec or size) will apply to the most recently added output. To process multiple outputs, use the .run() method instead of .save() or .stream().
var stream = fs.createWriteStream('outputfile.divx');
ffmpeg('/path/to/file.avi')
.output('outputfile.mp4')
.output(stream)
.on('end', function() {
console.log('Finished processing');
})
.run();The kill([signal='SIGKILL']) method sends a signal to the running ffmpeg process. This is only effective once processing has started. Sending a terminating signal will cause the error event to be emitted.
var command = ffmpeg('/path/to/video.avi')
.videoCodec('libx264')
.audioCodec('libmp3lame')
.on('start', function() {
// Send SIGSTOP to suspend ffmpeg
command.kill('SIGSTOP');
})
.save('/path/to/output.mp4');
// Kill ffmpeg after 60 seconds
setTimeout(function() {
command.on('error', function() {
console.log('Ffmpeg has been killed');
});
command.kill();
}, 60000);You can instantiate an FFmpeg command using the ffmpeg() constructor. You can pass an input file name, a readable stream, or a configuration object to the constructor.
Constructor Options:
source: input file name or readable stream (ignored if an input file is passed to the constructor).timeout: ffmpeg timeout in seconds (defaults to no timeout).preset or presets: directory to load module presets from.niceness or priority: ffmpeg niceness value between -20 and 20 (ignored on Windows; defaults to 0).logger: logger object with debug(), info(), warn(), and error() methods.stdoutLines: maximum number of lines from ffmpeg stdout/stderr to keep in memory (defaults to 100; use 0 for unlimited).Use fps(fps) to set the output framerate (e.g., 29.7). Use frames(count) to specify a fixed number of frames to encode.
ffmpeg('/path/to/file.avi').fps(29.7);
ffmpeg('/path/to/file.avi').frames(240);You can apply groups of settings to an FfmpegCommand using presets. There are two types:
Preset Modules: These are external files loaded from a directory. By default, they are loaded from the lib/presets subdirectory of fluent-ffmpeg. You can specify a custom directory using the presets option in the constructor. Preset modules must export a load(ffmpeg) function.
divx, flashvideo, podcast.Preset Functions: You can pass a custom function directly to .preset(). This function receives the FfmpegCommand as an argument and allows you to call any command methods on it.
// Using a preset module
ffmpeg('/path/to/file.avi').preset('divx');
// Using a custom directory for presets
ffmpeg('/path/to/file.avi', { presets: '/my/presets' }).preset('foo');
// Using a preset function
function myPreset(command) {
command.format('avi').size('720x?');
}
ffmpeg('/path/to/file.avi').preset(myPreset);