fluent-ffmpeg

repository·master·Indexed 27 days ago

https://github.com/fluent-ffmpeg/node-fluent-ffmpeg

A 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.

Tokens
8.5K
Snippets
21
Records
49
Agent score
93%

What's inside fluent-ffmpeg

  1. Regenerate JSDoc documentation

    master

    If 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 doc
  2. Configure FFmpeg and FFprobe binary paths

    master

    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.

  3. Add multiple outputs to a command

    master

    Use 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();
  4. Kill a running FFmpeg process

    master

    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);
  5. Create an FFmpeg command

    master

    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).
  6. Use preset modules or preset functions

    master

    You can apply groups of settings to an FfmpegCommand using presets. There are two types:

    1. 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.

      • Preinstalled presets: divx, flashvideo, podcast.
    2. 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);