### Install FFmpeg and Dependencies on Debian Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/wiki/Installing-ffmpeg-on-Debian This snippet provides a sequence of `apt-get` commands to add a multimedia repository, update package lists, install the repository keyring, and finally install FFmpeg along with the `libmp3lame0` library on Debian-based systems. ```bash $ apt-get update $ apt-get install debian-multimedia-keyring $ apt-get update $ apt-get install ffmpeg libmp3lame0 ``` -------------------------------- ### Handle fluent-ffmpeg 'start' Event Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Demonstrates how to listen for the 'start' event, which is emitted just after the FFmpeg process has been spawned. The event provides the full command line used as an argument. ```javascript ffmpeg('/path/to/file.avi') .on('start', function(commandLine) { console.log('Spawned Ffmpeg with command: ' + commandLine); }); ``` -------------------------------- ### Fluent-FFmpeg 'start' Event Documentation Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html Details the 'start' event emitted by the Fluent-FFmpeg processor, which signals that the FFmpeg process has been successfully spawned. It provides the full FFmpeg command line that was executed. ```APIDOC Event: start Description: Emitted just after ffmpeg has been spawned. Parameters: command: String - ffmpeg command line ``` -------------------------------- ### Handle Fluent-FFmpeg 'start' Event Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md The `start` event is emitted by `fluent-ffmpeg` just after the FFmpeg process has been spawned. It provides the full command line used as an argument, allowing users to log or inspect the exact command executed. ```javascript ffmpeg('/path/to/file.avi') .on('start', function(commandLine) { console.log('Spawned Ffmpeg with command: ' + commandLine); }); ``` -------------------------------- ### Test FFmpeg Installation Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/wiki/Installing-ffmpeg-on-Debian This command tests the FFmpeg installation by attempting to read information from a specified video file. A successful output indicates that FFmpeg is correctly installed and can access media files. ```bash $ ffmpeg -i /path/to/your/movie.avi ``` -------------------------------- ### Run Unit Tests for fluent-ffmpeg Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Executes the unit tests for the fluent-ffmpeg project using the `make` command. This requires npm dependencies to be installed beforehand. ```Shell $ make test ``` -------------------------------- ### Fluent-FFmpeg: Setting Output Format Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md Shows a simple example of setting the output format for a `fluent-ffmpeg` command using the `format()` method. ```JavaScript ffmpeg('/path/to/file.avi').format('flv'); ``` -------------------------------- ### Install fluent-ffmpeg via npm Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md This command installs the fluent-ffmpeg library using npm, the Node.js package manager. It's the standard way to add the library as a dependency to your Node.js project. ```sh npm install fluent-ffmpeg ``` -------------------------------- ### Install fluent-ffmpeg via npm Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Installs the fluent-ffmpeg library using Node Package Manager (npm). This command adds the package to your project's dependencies. ```Shell npm install fluent-ffmpeg ``` -------------------------------- ### Add Custom Output Options Examples Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html Examples demonstrating various ways to add custom output options to an FFmpeg command using the `outputOptions` method in fluent-ffmpeg. Options can be passed as single strings, multiple arguments, or an array of strings. ```javascript command.outputOptions('option1'); command.outputOptions('option1', 'option2'); command.outputOptions(['option1', 'option2']); ``` -------------------------------- ### Add Custom Input Options Examples Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html Examples demonstrating various ways to add custom input options to an FFmpeg command using the `inputOptions` method in fluent-ffmpeg. Options can be passed as single strings, multiple arguments, or an array of strings. ```javascript command.inputOptions('option1'); command.inputOptions('option1', 'option2'); command.inputOptions(['option1', 'option2']); ``` -------------------------------- ### Example fluent-ffmpeg DivX Preset Module Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md Illustrates the structure of a fluent-ffmpeg preset module, specifically the `divx` preset. It shows how the `load` function configures various FFmpeg options like format, video/audio bitrates, codecs, and output options. ```js exports.load = function(ffmpeg) { ffmpeg .format('avi') .videoBitrate('1024k') .videoCodec('mpeg4') .size('720x?') .audioBitrate('128k') .audioChannels(2) .audioCodec('libmp3lame') .outputOptions(['-vtag DIVX']); }; ``` -------------------------------- ### Fluent-FFmpeg `run()` Method API Reference Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Documents the `run()` method and its aliases (`exec()`, `execute()`) in the fluent-ffmpeg library. This method starts the FFmpeg processing, primarily useful when generating multiple outputs from a single command. It should not be used in conjunction with other processing methods like `save()`, `pipe()`, or `screenshots()`. ```APIDOC run() Aliases: exec(), execute() Description: Starts processing with the specified outputs. This method is mainly useful when producing multiple outputs. Parameters: - None Returns: - None (initiates asynchronous processing) Warning: - Do not use `run()` when calling other processing methods (e.g., `save()`, `pipe()`, or `screenshots()`). ``` -------------------------------- ### Querying FFmpeg Capabilities with fluent-ffmpeg Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md This snippet demonstrates how to use the `fluent-ffmpeg` library to programmatically retrieve information about the FFmpeg installation's supported formats, codecs, encoders, and filters. It shows both static method calls on the `Ffmpeg` object and instance method calls on a command object. ```js var Ffmpeg = require('fluent-ffmpeg'); Ffmpeg.getAvailableFormats(function(err, formats) { console.log('Available formats:'); console.dir(formats); }); Ffmpeg.getAvailableCodecs(function(err, codecs) { console.log('Available codecs:'); console.dir(codecs); }); Ffmpeg.getAvailableEncoders(function(err, encoders) { console.log('Available encoders:'); console.dir(encoders); }); Ffmpeg.getAvailableFilters(function(err, filters) { console.log("Available filters:"); console.dir(filters); }); // Those methods can also be called on commands new Ffmpeg({ source: '/path/to/file.avi' }) .getAvailableCodecs(...); ``` -------------------------------- ### Fluent-FFmpeg Capability Query Methods Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html These methods allow querying FFmpeg for its available codecs, encoders, filters, and formats. They are asynchronous operations that require a callback function to process the results. Each method also has an alias prefixed with 'get'. ```APIDOC availableCodecs(callback) - Description: Query ffmpeg for available codecs - Parameters: - callback: FfmpegCommand~codecCallback - callback function - Alias: getAvailableCodecs availableEncoders(callback) - Description: Query ffmpeg for available encoders - Parameters: - callback: FfmpegCommand~encodersCallback - callback function - Alias: getAvailableEncoders availableFilters(callback) - Description: Query ffmpeg for available filters - Parameters: - callback: FfmpegCommand~filterCallback - callback function - Alias: getAvailableFilters availableFormats(callback) - Description: Query ffmpeg for available formats - Parameters: - callback: FfmpegCommand~formatCallback - callback function - Alias: getAvailableFormats ``` -------------------------------- ### Fluent-FFmpeg: Using `outputOptions()` for Custom FFmpeg Flags Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md Provides examples of how to apply custom FFmpeg output options using `outputOptions()`, demonstrating its flexibility for single options, options with parameters, and multiple options passed as an array or separate arguments. ```JavaScript /* Single option */ ffmpeg('/path/to/file.avi').outputOptions('-someOption'); /* Single option with parameter */ ffmpeg('/dev/video0').outputOptions('-r 24'); ffmpeg('/path/to/file.avi').outputOptions([ '-option1', '-option2 param2', '-option3', '-option4 param4' ]); ffmpeg('/path/to/file.avi').outputOptions( '-option1', '-option2', 'param2', '-option3', '-option4', 'param4' ); ``` -------------------------------- ### Execute FFmpeg Command for Multiple Outputs in Node.js Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Demonstrates how to use the `run()` method in fluent-ffmpeg to generate multiple output files from a single input. This example creates a screenshot, a small AVI, and a big AVI from an input video, showcasing different output configurations within one command chain. ```JavaScript ffmpeg('/path/to/file.avi') .output('screenshot.png') .noAudio() .seek('3:00') .output('small.avi') .audioCodec('copy') .size('320x200') .output('big.avi') .audioCodec('copy') .size('640x480') .on('error', function(err) { console.log('An error occurred: ' + err.message); }) .on('end', function() { console.log('Processing finished !'); }) .run(); ``` -------------------------------- ### fluent-ffmpeg Output Streaming with stream() Method Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/wiki/Migrating-from-fluent-ffmpeg-1.x Demonstrates how to stream output from fluent-ffmpeg using the `stream()` method. It shows examples of passing a writable stream directly or allowing fluent-ffmpeg to create and return a PassThrough stream for piping. ```javascript var ffmpeg = require('fluent-ffmpeg'); var outStream = require('fs').createWriteStream('out.avi'); // Passing a readable stream ffmpeg('input.avi').stream(outStream); // Not passing a readable stream var stream = ffmpeg('input.avi').stream(); stream.pipe(outStream); ``` -------------------------------- ### Cloning an FfmpegCommand Instance for Multiple Outputs Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md This example demonstrates how to use the `clone()` method on an `FfmpegCommand` instance. Cloning allows you to create exact copies of a command at a specific point, enabling you to apply different processing options (e.g., varying output sizes) to the same input without affecting the original command or other clones. ```js // Create a command to convert source.avi to MP4 var command = ffmpeg('/path/to/source.avi') .audioCodec('libfaac') .videoCodec('libx264') .format('mp4'); // Create a clone to save a small resized version command.clone() .size('320x200') .save('/path/to/output-small.mp4'); // Create a clone to save a medium resized version command.clone() .size('640x400') .save('/path/to/output-medium.mp4'); // Save a converted version with the original size command.save('/path/to/output-original-size.mp4'); ``` -------------------------------- ### Fluent-FFmpeg Library Features and Usage Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/ffprobe.js.html This section outlines the key features and functionalities provided by the `node-fluent-ffmpeg` library. It covers various aspects of FFmpeg command creation, input/output specification, audio/video options, event handling, process control, and metadata reading, serving as a comprehensive guide to using the library. ```APIDOC Fluent-FFmpeg Features: - Installation: Instructions for setting up the library. - Usage: General guidelines for using the library. - Prerequisites: Dependencies required for the library to function. - Creating an FFmpeg command: How to initialize and configure FFmpeg commands. - Specifying inputs: Methods for defining input sources. - Input options: Configuration options specific to input streams. - Audio options: Settings for audio processing. - Video options: Settings for video processing. - Video frame size options: Options related to video resolution and aspect ratio. - Specifying multiple outputs: How to configure multiple output files or streams. - Output options: Configuration options specific to output streams. - Miscellaneous options: Other general-purpose options. - Setting event handlers: How to register callbacks for various FFmpeg events. - Starting FFmpeg processing: Initiating the FFmpeg command execution. - Controlling the FFmpeg process: Methods for managing the running FFmpeg process (e.g., pausing, stopping). - Reading video metadata: How to extract metadata from media files using ffprobe. - Querying ffmpeg capabilities: Checking available codecs, formats, etc. - Cloning an FfmpegCommand: Duplicating an existing command instance. Contributing: - Code contributions: Guidelines for contributing code to the project. - Documentation contributions: How to contribute to the project's documentation. - Updating the documentation: Steps for updating existing documentation. - Running tests: Instructions for executing the project's test suite. Main contributors: List of primary contributors. License: Licensing information for the project. ``` -------------------------------- ### Generate Thumbnails with fluent-ffmpeg in Node.js Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Demonstrates how to use the `screenshots()` method in `fluent-ffmpeg` to extract multiple thumbnails from a video. The examples show generating a fixed `count` of thumbnails and generating thumbnails at specific `timestamps`, along with custom filename patterns and output folders. It also illustrates handling the `filenames` and `end` events. ```JavaScript ffmpeg('/path/to/video.avi') .on('filenames', function(filenames) { console.log('Will generate ' + filenames.join(', ')) }) .on('end', function() { console.log('Screenshots taken'); }) .screenshots({ // Will take screens at 20%, 40%, 60% and 80% of the video count: 4, folder: '/path/to/output' }); ffmpeg('/path/to/video.avi') .screenshots({ timestamps: [30.5, '50%', '01:10.123'], filename: 'thumbnail-at-%s-seconds.png', folder: '/path/to/output', size: '320x240' }); ``` -------------------------------- ### Save fluent-ffmpeg Output to File Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Illustrates how to start FFmpeg processing and save the output to a specified file using the `save()` method (or its alias `saveToFile()`). This example also integrates error and end event handling for robust processing. ```javascript ffmpeg('/path/to/file.avi') .videoCodec('libx264') .audioCodec('libmp3lame') .size('320x240') .on('error', function(err) { console.log('An error occurred: ' + err.message); }) .on('end', function() { console.log('Processing finished !'); }) .save('/path/to/output.mp4'); ``` -------------------------------- ### Change FFmpeg Process Priority with renice() in Node.js Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Shows how to use the `renice()` method to adjust the operating system priority (niceness) of the FFmpeg process. The examples demonstrate setting the niceness at the start of the command chain and dynamically changing it for a running process, highlighting its impact on process scheduling. ```JavaScript // Set startup niceness var command = ffmpeg('/path/to/file.avi') .renice(5) .save('/path/to/output.mp4'); // Command takes too long, raise its priority setTimeout(function() { command.renice(-5); }, 60000); ``` -------------------------------- ### Fluent-FFmpeg `run()` Method API Reference Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md Detailed API documentation for the `run()` method in `node-fluent-ffmpeg`, including its aliases and primary use case for initiating processing with multiple output configurations. ```APIDOC run(): start processing - Aliases: `exec()`, `execute()` - Description: Initiates the FFmpeg processing with all specified inputs and outputs. This method is primarily useful when producing multiple outputs. - Parameters: None. - Returns: The `ffmpeg` command instance for chaining. - Warning: Do not use `run()` when calling other processing methods like `save()`, `pipe()`, or `screenshots()`, as these methods implicitly call `run()`. ``` -------------------------------- ### Install FFmpeg on macOS using Homebrew Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/wiki/Installing-ffmpeg-on-Mac-OS-X This command installs the FFmpeg multimedia framework on macOS systems using the Homebrew package manager. Homebrew simplifies the installation process and typically includes common codecs like H.264. ```Shell brew install ffmpeg ``` -------------------------------- ### Instantiating fluent-ffmpeg Commands Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md Demonstrates various ways to create an FFmpeg command instance using the fluent-ffmpeg module, including using the 'new' operator, calling the constructor directly, and passing initial input files, streams, or configuration objects. ```javascript var FfmpegCommand = require('fluent-ffmpeg'); var command = new FfmpegCommand(); ``` ```javascript var ffmpeg = require('fluent-ffmpeg'); var command = ffmpeg(); ``` ```javascript var command = ffmpeg('/path/to/file.avi'); var command = ffmpeg(fs.createReadStream('/path/to/file.avi')); var command = ffmpeg({ option: "value", ... }); var command = ffmpeg('/path/to/file.avi', { option: "value", ... }); ``` -------------------------------- ### FfmpegCommand Execution Methods Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/processor.js.html Documentation for the `FfmpegCommand` methods used to initiate the FFmpeg process. These methods (`run`, `exec`, `execute`) are aliases for the same functionality, which involves preparing the command, spawning the FFmpeg process, and managing its lifecycle including input/output streams and event emission. ```APIDOC FfmpegCommand#run() FfmpegCommand#exec() FfmpegCommand#execute() - Description: Initiates the FFmpeg command execution. - Category: Processing - Aliases: exec, execute (for run) - Behavior: - Checks for at least one output specified. - Identifies and manages input/output streams (if any). - Prepares command arguments via `_prepare` (an internal method). - Spawns the FFmpeg process using `_spawnFfmpeg` (an internal method). - Pipes input stream to FFmpeg's stdin if an input stream is provided. - Emits 'start' event with the full command string (e.g., 'ffmpeg -i input.mp4 output.mp4'). - Emits 'end' on successful completion or 'error' on failure, ensuring only one final event is emitted. - Throws: Error if no output is specified (e.g., `new Error('No output specified')`). ``` -------------------------------- ### fluent-ffmpeg Constructor with First Argument Input Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/wiki/Migrating-from-fluent-ffmpeg-1.x Illustrates passing the initial input file directly as the first argument to the fluent-ffmpeg constructor, optionally followed by an options object. This provides a more concise way to initialize a command with a primary input. ```javascript var Ffmpeg = require('fluent-ffmpeg'); var command1 = new Ffmpeg('input.avi'); var command2 = new Ffmpeg('input.avi', { timeout: 30 }); var command3 = new Ffmpeg({ source: 'input.avi', timeout: 30 }); ``` -------------------------------- ### FfmpegCommand Preset and usingPreset API Reference Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/misc.js.html Documentation for the `preset` and `usingPreset` methods of the `FfmpegCommand` class in `node-fluent-ffmpeg`. These methods allow applying predefined configurations by name or custom functions to an FFmpeg command instance. ```APIDOC FfmpegCommand#preset(preset) FfmpegCommand#usingPreset(preset) - Description: Use a preset configuration for the FFmpeg command. - Category: Miscellaneous - Parameters: - preset: (String|Function) The preset to apply. - If String: Name of a preset module to load. The module must export a `load` function. - If Function: A function that takes the FfmpegCommand instance as its argument and applies configurations. - Returns: (FfmpegCommand) The current FfmpegCommand instance for chaining. - Throws: - Error: If a string preset name is provided but the module cannot be loaded or does not have a `load()` function. ``` -------------------------------- ### fluent-ffmpeg Constructor with input() and addInput() Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/wiki/Migrating-from-fluent-ffmpeg-1.x Demonstrates the new flexible constructor syntax for fluent-ffmpeg, allowing inputs to be added later using `input()` or `addInput()` methods. This allows for creating a command object first and then chaining input specifications. ```javascript var Ffmpeg = require('fluent-ffmpeg'); var command1 = new Ffmpeg().input('input1.avi').input('input2.avi'); var command2 = new Ffmpeg({ timeout: 30 }).input('input1.avi'); var command3 = new Ffmpeg({ timeout: 30 }).addInput('input1.avi'); ``` -------------------------------- ### Spawn FFmpeg Process Implementation in Fluent-FFmpeg Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/processor.js.html This JavaScript code implements the `_spawnFfmpeg` method, which is responsible for initiating the FFmpeg process. It handles flexible argument parsing for options and callbacks, finds the FFmpeg executable path, and prepares the environment for process spawning, including applying niceness settings. ```javascript proto._spawnFfmpeg = function(args, options, processCB, endCB) { // Enable omitting options if (typeof options === 'function') { endCB = processCB; processCB = options; options = {}; } // Enable omitting processCB if (typeof endCB === 'undefined') { endCB = processCB; processCB = function() {}; } var maxLines = 'stdoutLines' in options ? options.stdoutLines : this.options.stdoutLines; // Find ffmpeg this._getFfmpegPath(function(err, command) { if (err) { return endCB(err); } else if (!command || command.length === 0) { return endCB(new Error('Cannot find ffmpeg')); } // Apply niceness }); } ``` -------------------------------- ### Node.js Module Initialization and Dependencies Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/recipes.js.html Initializes the `recipes.js` module for `fluent-ffmpeg`, importing necessary Node.js core modules like `fs`, `path`, `stream`, and external libraries like `async` and `utils`. This sets up the environment for defining `FfmpegCommand` prototypes. ```JavaScript /*jshint node:true*/ 'use strict'; var fs = require('fs'); var path = require('path'); var PassThrough = require('stream').PassThrough; var async = require('async'); var utils = require('./utils'); /* * Useful recipes for commands */ module.exports = function recipes(proto) { ``` -------------------------------- ### FfmpegCommand Constructor and Initialization Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/fluent-ffmpeg.js.html Documents the `FfmpegCommand` constructor, which is used to create new FFmpeg command instances. It explains how to pass input sources and various configuration options, including logging, niceness, preset directories, and output line limits. The constructor handles optional 'new' operator usage and initializes internal properties for managing inputs and outputs. ```APIDOC FfmpegCommand(input, options) Create an ffmpeg command instance. Can be called with or without the 'new' operator. Parameters: input: {String|ReadableStream} [optional] - Input file path or readable stream. options: {Object} [optional] - Command options. options.logger: {Object} [default: ] - Logger object with 'error', 'warning', 'info', and 'debug' methods. options.niceness: {Number} [default: 0] - FFmpeg process niceness (ignored on Windows). options.priority: {Number} [alias for niceness] - Alias for `niceness`. options.presets: {String} [default: "fluent-ffmpeg/lib/presets"] - Directory to load presets from. options.preset: {String} [alias for presets] - Alias for `presets`. options.stdoutLines: {Number} [default: 100] - Maximum lines of FFmpeg output to keep in memory (0 for unlimited). options.timeout: {Number} [default: ] - FFmpeg processing timeout in seconds. options.source: {String|ReadableStream} [alias for input] - Alias for the `input` parameter. Returns: {FfmpegCommand} - A new FfmpegCommand instance. Example Usage (Internal): function FfmpegCommand(input, options) { if (!(this instanceof FfmpegCommand)) { return new FfmpegCommand(input, options); } // ... initialization logic ... this._inputs = []; if (options.source) { this.input(options.source); } this._outputs = []; this.output(); // ... option defaults and logger setup ... } util.inherits(FfmpegCommand, EventEmitter); module.exports = FfmpegCommand; ``` -------------------------------- ### FFmpeg Complex Filter Graph Example Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/custom.js.html Demonstrates how to construct a complex filter graph using `fluent-ffmpeg` to manipulate video streams. This example shows operations like color channel manipulation (`lutrgb`), padding (`pad`), and overlaying multiple streams (`overlay`) to create a composite video output. ```javascript [ // Create stream 'red' by cancelling green and blue channels from stream 'a' { filter: 'lutrgb', options: { g: 0, b: 0 }, inputs: 'a', outputs: 'red' }, // Create stream 'green' by cancelling red and blue channels from stream 'b' { filter: 'lutrgb', options: { r: 0, b: 0 }, inputs: 'b', outputs: 'green' }, // Create stream 'blue' by cancelling red and green channels from stream 'c' { filter: 'lutrgb', options: { r: 0, g: 0 }, inputs: 'c', outputs: 'blue' }, // Pad stream 'red' to 3x width, keeping the video on the left, and name output 'padded' { filter: 'pad', options: { w: 'iw*3', h: 'ih' }, inputs: 'red', outputs: 'padded' }, // Overlay 'green' onto 'padded', moving it to the center, and name output 'redgreen' { filter: 'overlay', options: { x: 'w', y: 0 }, inputs: ['padded', 'green'], outputs: 'redgreen'}, // Overlay 'blue' onto 'redgreen', moving it to the right { filter: 'overlay', options: { x: '2*w', y: 0 }, inputs: ['redgreen', 'blue']} ] ``` -------------------------------- ### fluent-ffmpeg 1.x vs 2.x Method Aliases Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/wiki/Migrating-from-fluent-ffmpeg-1.x Compares method usage between fluent-ffmpeg 1.x and 2.x, highlighting the new, shorter aliases introduced in version 2.x while maintaining backward compatibility. This demonstrates the streamlined API for common operations like setting size, applying presets, and saving. ```javascript // 1.x code var Ffmpeg = require('fluent-ffmpeg'); new Ffmpeg({source:'file.avi'}) .withSize('320x?') .usingPreset('flashvideo') .saveToFile('out.avi'); // 2.x code var ffmpeg = require('fluent-ffmpeg'); ffmpeg('file.avi') .size('320x?') .preset('flashvideo') .save('out.avi'); ``` -------------------------------- ### Example structure of ffprobe JSON metadata output Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Presents a comprehensive example of the JSON object returned by `ffprobe`, detailing the structure for both stream-specific information (e.g., codec, resolution, duration) and overall format information (e.g., filename, total duration, bit rate). It includes nested objects for disposition and tags. ```JSON { "streams": [ { "index": 0, "codec_name": "h264", "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", "profile": "Constrained Baseline", "codec_type": "video", "codec_time_base": "1/48", "codec_tag_string": "avc1", "codec_tag": "0x31637661", "width": 320, "height": 180, "has_b_frames": 0, "sample_aspect_ratio": "1:1", "display_aspect_ratio": "16:9", "pix_fmt": "yuv420p", "level": 13, "r_frame_rate": "24/1", "avg_frame_rate": "24/1", "time_base": "1/24", "start_pts": 0, "start_time": "0.000000", "duration_ts": 14315, "duration": "596.458333", "bit_rate": "702655", "nb_frames": "14315", "disposition": { "default": 0, "dub": 0, "original": 0, "comment": 0, "lyrics": 0, "karaoke": 0, "forced": 0, "hearing_impaired": 0, "visual_impaired": 0, "clean_effects": 0, "attached_pic": 0 }, "tags": { "creation_time": "1970-01-01 00:00:00", "language": "und", "handler_name": "\fVideoHandler" } }, { "index": 1, "codec_name": "aac", "codec_long_name": "AAC (Advanced Audio Coding)", "codec_type": "audio", "codec_time_base": "1/48000", "codec_tag_string": "mp4a", "codec_tag": "0x6134706d", "sample_fmt": "fltp", "sample_rate": "48000", "channels": 2, "bits_per_sample": 0, "r_frame_rate": "0/0", "avg_frame_rate": "0/0", "time_base": "1/48000", "start_pts": 0, "start_time": "0.000000", "duration_ts": 28619776, "duration": "596.245333", "bit_rate": "159997", "nb_frames": "27949", "disposition": { "default": 0, "dub": 0, "original": 0, "comment": 0, "lyrics": 0, "karaoke": 0, "forced": 0, "hearing_impaired": 0, "visual_impaired": 0, "clean_effects": 0, "attached_pic": 0 }, "tags": { "creation_time": "1970-01-01 00:00:00", "language": "und", "handler_name": "\fSoundHandler" } } ], "format": { "filename": "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", "nb_streams": 2, "format_name": "mov,mp4,m4a,3gp,3g2,mj2", "format_long_name": "QuickTime / MOV", "start_time": "0.000000", "duration": "596.459000", "size": "64657027", "bit_rate": "867211", "tags": { "major_brand": "isom", "minor_version": "512", "compatible_brands": "mp41", "creation_time": "1970-01-01 00:00:00", "title": "Big Buck Bunny", "artist": "Blender Foundation", "composer": "Blender Foundation", "date": "2008", "encoder": "Lavf52.14.0" } } } ``` -------------------------------- ### Configure FFmpeg and FFprobe Binary Paths Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html Methods to manually specify the full paths for the `ffprobe` and `flvtool2`/`flvmeta` binaries used by `node-fluent-ffmpeg`. These are typically set once during application initialization. ```APIDOC setFfprobePath(ffprobePath) Manually define the ffprobe binary full path. Parameters: ffprobePath: String - The full path to the ffprobe binary. Returns: FfmpegCommand setFlvtoolPath(flvtool) Manually define the flvtool2/flvmeta binary full path. Parameters: flvtool: String - The full path to the flvtool2 or flvmeta binary. Returns: FfmpegCommand ``` -------------------------------- ### Fluent-FFmpeg: Setting Output Duration Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/README.md Examples demonstrating how to set the output duration for an FFmpeg command using `fluent-ffmpeg`, accepting both numeric seconds and timestamp strings. ```JavaScript ffmpeg('/path/to/file.avi').duration(134.5); ffmpeg('/path/to/file.avi').duration('2:14.500'); ``` -------------------------------- ### Generate Test Coverage Report for fluent-ffmpeg Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/index.html Generates a test coverage report for the fluent-ffmpeg project, which is then filed under `test/coverage.html`. An up-to-date ffmpeg installation is recommended to prevent issues. ```Shell $ make test-cov ``` -------------------------------- ### Implement FfmpegCommand preset/usingPreset Method Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/options_misc.js.html This JavaScript code defines the `preset` and `usingPreset` methods for the `FfmpegCommand` prototype in `node-fluent-ffmpeg`. It allows users to apply predefined configurations (presets) to an FFmpeg command, either by calling a function or loading a module from a specified path. ```javascript module.exports = function(proto) { proto.usingPreset = proto.preset = function(preset) { if (typeof preset === 'function') { preset(this); } else { try { var modulePath = path.join(this.options.presets, preset); var module = require(modulePath); if (typeof module.load === 'function') { module.load(this); } else { throw new Error('preset ' + modulePath + ' has no load() function'); } } catch (err) { throw new Error('preset ' + modulePath + ' could not be loaded: ' + err.message); } } return this; }; }; ``` -------------------------------- ### Example JavaScript Function Call Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/options_custom.js.html A simple JavaScript function call, likely used in the context of documentation generation or display, possibly to format or render content. ```JavaScript prettyPrint(); ``` -------------------------------- ### Set Output Seek Time for FfmpegCommand Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/output.js.html Specifies the seek time for the current output. This is equivalent to the FFmpeg `-ss` option, allowing users to define a starting point for the output. ```APIDOC FfmpegCommand#seek(seek) FfmpegCommand#seekOutput(seek) - Description: Specify the output seek time. - Category: Input (affects output seek) - Parameters: - seek: {String|Number} Seek time in seconds or as a '[hh:[mm:]]ss[.xxx]' string. Required. - Returns: FfmpegCommand (for chaining) ``` -------------------------------- ### FfmpegCommand Class Constructor and Properties Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html Documents the constructor for the `FfmpegCommand` class in `fluent-ffmpeg`, including its input parameters and configurable properties like logger, niceness, presets, stdoutLines, and timeout. ```APIDOC Class: FfmpegCommand new FfmpegCommand(input, options) Create an ffmpeg command. Can be called with or without the 'new' operator, and the 'input' parameter may be specified as 'options.source' instead (or passed later with the addInput method). Parameters: input: String | ReadableStream (optional) - input file path or readable stream. options: Object (optional) - command options. Properties: logger: Object (optional, default: ) - logger object with 'error', 'warning', 'info' and 'debug' methods. niceness: Number (optional, default: 0) - ffmpeg process niceness, ignored on Windows. priority: Number (optional, default: 0) - alias for niceness. presets: String (optional, default: "fluent-ffmpeg/lib/presets") - directory to load presets from. preset: String (optional, default: "fluent-ffmpeg/lib/presets") - alias for presets. stdoutLines: String (optional, default: 100) - maximum lines of ffmpeg output to keep in memory, use 0 for unlimited. timeout: Number (optional, default: ) - ffmpeg processing timeout in seconds. source: String | ReadableStream (optional, default: ) - alias for the input parameter. ``` -------------------------------- ### Specify Output Seek Time for FfmpegCommand Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html Sets the seek time for the output stream. This allows starting the output at a specific point in the source media, specified in seconds or as a time string. ```APIDOC seek(seek) - Parameters: - seek: String | Number - seek time in seconds or as a '[hh:[mm:]]ss[.xxx]' string - Returns: FfmpegCommand - Alias: seekOutput ``` -------------------------------- ### fluent-ffmpeg Multiple Outputs with run() Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/wiki/Migrating-from-fluent-ffmpeg-1.x Illustrates how to configure multiple outputs for a single fluent-ffmpeg command using the `output()` method, which accepts both filenames and writable streams. It demonstrates applying output-specific options and initiating the processing with `run()`. ```javascript var outStream = require('fs').createWriteStream('videotrack.avi'); ffmpeg('input.avi') .output('audiotrack.mp3') // Apply to 'audiotrack.mp3' .noVideo() .audioCodec('libmp3lame') // An optional pipe() options object can be passed here .output(outStream, { end: true }) // Applies to outStream (videotrack.avi) .noAudio() .videoCodec('libx264') .on('end', function() { console.log('Finished processing'); }) .run(); ``` -------------------------------- ### Define Complex Filtergraphs with FfmpegCommand Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/options_custom.js.html Examples demonstrating how to use the `complexFilter` method to define intricate video and audio processing pipelines in `node-fluent-ffmpeg`, including overlaying images and splitting video channels. ```JavaScript ffmpeg() .input('video.avi') .input('image.png') .complexFilter('[0:v][1:v]overlay[out]', ['out']); ``` ```JavaScript ffmpeg() .input('video.avi') .input('image.png') .complexFilter([{ filter: 'overlay', inputs: ['0:v', '1:v'], outputs: ['out'] }], ['out']); ``` ```JavaScript ffmpeg() .input('video.avi') .complexFilter([ // Duplicate video stream 3 times into streams a, b, and c { filter: 'split', options: '3', outputs: ['a', 'b', 'c'] }, // Create stream 'red' by cancelling green and blue channels from stream 'a' { filter: 'lutrgb', options: { g: 0, b: 0 }, inputs: 'a', outputs: 'red' } ]); ``` -------------------------------- ### FfmpegCommand preset/usingPreset API Reference Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/options_misc.js.html API documentation for the `preset` and `usingPreset` methods of the `FfmpegCommand` class in `node-fluent-ffmpeg`. These methods allow applying predefined configurations to an FFmpeg command, accepting either a preset name (string) or a function. ```APIDOC FfmpegCommand#preset(preset) FfmpegCommand#usingPreset(preset) - Description: Applies a predefined configuration (preset) to the FFmpeg command instance. - Category: Miscellaneous - Aliases: usingPreset - Parameters: - preset: {String|Function} - Description: The preset to apply. This can be: - A String: The name of a preset module to load. The module is expected to be found in the configured preset path and must export a `load()` function. - A Function: A function that directly takes the `FfmpegCommand` instance as its argument and applies configurations. - Returns: The current `FfmpegCommand` instance (for method chaining). - Behavior: - If `preset` is a function, it is executed with the `FfmpegCommand` instance as `this`. - If `preset` is a string, the method attempts to `require` the corresponding module. If the module is found and exports a `load` function, `load(this)` is called. - Errors: Throws an `Error` if the string-based preset module cannot be loaded or if it does not export a `load()` function. ``` -------------------------------- ### FfmpegCommand Aliases for Configuration Methods Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html These methods are aliases for common FfmpegCommand configuration methods, providing alternative syntax for setting aspect ratio, autopadding, and output size. ```APIDOC withAspect(aspect) - Alias for FfmpegCommand#aspect withAspectRatio(aspect) - Alias for FfmpegCommand#aspect withAutoPad(pad, color) - Alias for FfmpegCommand#autopad withAutopad(pad, color) - Alias for FfmpegCommand#autopad withAutopadding(pad, color) - Alias for FfmpegCommand#autopad withAutoPadding(pad, color) - Alias for FfmpegCommand#autopad withSize(size) - Alias for FfmpegCommand#size ``` -------------------------------- ### Add Custom Output Options to FfmpegCommand Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/options_custom.js.html Examples demonstrating how to use the `outputOptions` method to add custom options to an FFmpeg command, supporting single options, multiple arguments, and array inputs. ```JavaScript command.outputOptions('option1'); ``` ```JavaScript command.outputOptions('option1', 'option2'); ``` ```JavaScript command.outputOptions(['option1', 'option2']); ``` -------------------------------- ### Add Custom Input Options to FfmpegCommand Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/options_custom.js.html Examples demonstrating how to use the `inputOptions` method to add custom options to an FFmpeg command, supporting single options, multiple arguments, and array inputs. ```JavaScript command.inputOptions('option1'); ``` ```JavaScript command.inputOptions('option1', 'option2'); ``` ```JavaScript command.inputOptions(['option1', 'option2']); ``` -------------------------------- ### Prepare FFmpeg Command Execution Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/processor.js.html This method prepares an FFmpeg command for execution. It performs prerequisite checks, such as verifying codec and format availability, and then constructs the full argument list for FFmpeg. The generated arguments are subsequently passed to a provided callback function. ```APIDOC FfmpegCommand#_prepare(callback, [readMetadata=false]) - Description: Checks prerequisites for the execution of the command (codec/format availability, flvtool...), then builds the argument list for ffmpeg and pass them to 'callback'. - Parameters: - callback: {Function} Callback with signature (err, args). - readMetadata: {Boolean} [Optional, default=false] Read metadata before processing. ``` -------------------------------- ### Specify Input Seek Time for FfmpegCommand Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/inputs.js.html Sets the starting seek time for the last specified input. This allows FFmpeg to begin processing the input from a specific point in time, specified in seconds or as a time string. ```APIDOC FfmpegCommand#seekInput(seek) - Specify input seek time for the last specified input - Aliases: setStartTime, seekTo - Parameters: - seek: {String|Number} seek time in seconds or as a '[hh:[mm:]]ss[.xxx]' string - Returns: FfmpegCommand ``` ```javascript proto.setStartTime = proto.seekInput = function(seek) { if (!this._currentInput) { throw new Error('No input specified'); } this._currentInput.options('-ss', seek); return this; }; ``` -------------------------------- ### Specify Input Seek Time for FfmpegCommand Source: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/doc/FfmpegCommand.html Sets the seek time for the last specified input stream. This allows starting processing from a specific point within the input media, specified in seconds or as a time string. ```APIDOC seekInput(seek) - Parameters: - seek: String | Number - seek time in seconds or as a '[hh:[mm:]]ss[.xxx]' string - Returns: FfmpegCommand - Aliases: setStartTime, seekTo ```