CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-fluent-ffmpeg

A fluent API to FFMPEG for audio and video manipulation with chainable methods

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Fluent-FFmpeg

Fluent-FFmpeg is a Node.js library that provides a fluent API wrapper for FFmpeg, enabling audio and video manipulation through chainable JavaScript methods. It abstracts complex FFmpeg command-line usage into an intuitive JavaScript interface with comprehensive event handling and streaming support.

Package Information

  • Package Name: fluent-ffmpeg
  • Package Type: npm
  • Language: JavaScript (Node.js)
  • Installation: npm install fluent-ffmpeg

Core Imports

const ffmpeg = require('fluent-ffmpeg');

ES6 modules:

import ffmpeg from 'fluent-ffmpeg';

Basic Usage

const ffmpeg = require('fluent-ffmpeg');

// Basic video conversion
ffmpeg('input.avi')
  .output('output.mp4')
  .on('end', () => console.log('Processing finished'))
  .on('error', (err) => console.error('Error:', err))
  .run();

// Audio extraction with format conversion
ffmpeg('video.mp4')
  .noVideo()
  .audioCodec('libmp3lame')
  .save('audio.mp3');

// Video processing with size and codec options
ffmpeg('input.mov')
  .videoCodec('libx264')
  .size('640x480')
  .fps(25)
  .audioBitrate('128k')
  .save('output.mp4');

Architecture

Fluent-FFmpeg is built around several key components:

  • FfmpegCommand Class: Main command builder that inherits from EventEmitter
  • Method Chaining: All configuration methods return the command instance for fluent usage
  • Event System: Comprehensive progress tracking and error handling via events
  • Stream Support: Full integration with Node.js streams for input and output
  • Plugin Architecture: Extensible preset system for common configurations
  • Binary Management: Automatic detection and configuration of FFmpeg binaries

Capabilities

Input Management

Configure input sources, formats, and processing parameters.

// Add input source (file path or stream)
input(source) // → FfmpegCommand
// Aliases: addInput, mergeAdd

// Specify input format
inputFormat(format) // → FfmpegCommand  
// Aliases: withInputFormat, fromFormat

// Set input seeking position
seekInput(seek) // → FfmpegCommand
// Aliases: setStartTime

Input Management

Audio Processing

Complete audio manipulation including codecs, bitrates, channels, and filters.

// Audio codec configuration
audioCodec(codec) // → FfmpegCommand
// Aliases: withAudioCodec

// Audio quality settings
audioBitrate(bitrate) // → FfmpegCommand
audioChannels(channels) // → FfmpegCommand
audioFrequency(freq) // → FfmpegCommand

// Audio filters
audioFilters(...filters) // → FfmpegCommand
// Aliases: withAudioFilter, withAudioFilters, audioFilter

Audio Processing

Video Processing

Comprehensive video manipulation including codecs, bitrates, size, and filters.

// Video codec configuration
videoCodec(codec) // → FfmpegCommand
// Aliases: withVideoCodec

// Video quality and format
videoBitrate(bitrate, constant?) // → FfmpegCommand
fps(fps) // → FfmpegCommand
frames(frames) // → FfmpegCommand

// Video filters
videoFilters(...filters) // → FfmpegCommand
// Aliases: withVideoFilter, withVideoFilters, videoFilter

Video Processing

Output Management

Configure output destinations, formats, and processing parameters.

// Add output target
output(target?, pipeopts?) // → FfmpegCommand
// Aliases: addOutput

// Output format and seeking
format(format) // → FfmpegCommand
seek(seek) // → FfmpegCommand
duration(duration) // → FfmpegCommand

// Stream mapping
map(spec) // → FfmpegCommand

Output Management

Processing Control

Execute commands with full control over the FFmpeg process.

// Execute command
run() // → FfmpegCommand

// Save to file
save(output) // → FfmpegCommand
// Aliases: saveToFile

// Pipe to stream
pipe(stream?, options?) // → WritableStream
// Aliases: stream, writeToStream

// Process control
kill(signal?) // → FfmpegCommand

Processing Control

Special Features

Advanced functionality including screenshots, concatenation, and metadata analysis.

// Generate screenshots
screenshots(config, folder?) // → FfmpegCommand
// Aliases: takeScreenshots, thumbnail, thumbnails, screenshot

// Concatenate inputs
concat(target, options?) // → FfmpegCommand
// Aliases: concatenate, mergeToFile

// Probe input metadata
ffprobe(index?, options?, callback) // → void

Special Features

Configuration

Binary paths, capability queries, and preset management.

// Binary path configuration
setFfmpegPath(path) // → FfmpegCommand
setFfprobePath(path) // → FfmpegCommand
setFlvtoolPath(path) // → FfmpegCommand

// Capability queries
availableFilters(callback) // → void
availableCodecs(callback) // → void
availableFormats(callback) // → void

// Preset application
preset(preset) // → FfmpegCommand
// Aliases: usingPreset

Configuration

Types

/**
 * Main FFmpeg command class
 * @extends EventEmitter
 */
class FfmpegCommand extends EventEmitter {
  constructor(input?, options?)
}

/**
 * Logger interface for debugging and monitoring
 */
interface Logger {
  debug(message: string): void;
  info(message: string): void;
  warn(message: string): void;
  error(message: string): void;
}

/**
 * Constructor options
 */
interface FfmpegOptions {
  logger?: Logger;           // Logger with debug/info/warn/error methods
  niceness?: number;         // Process niceness (-20 to 20) 
  priority?: number;         // Alias for niceness
  presets?: string;          // Preset directory path
  preset?: string;           // Alias for presets
  stdoutLines?: number;      // Max stdout lines (default: 100)
  timeout?: number;          // Processing timeout in seconds
  source?: string|ReadableStream; // Alias for input parameter
}

/**
 * Progress information emitted during processing
 */
interface ProgressInfo {
  frames: number;           // Transcoded frames
  currentFps: number;       // Current FPS
  currentKbps: number;      // Current speed (kbps)
  targetSize: number;       // Output size in KB
  timemark: string;         // Current time (HH:MM:SS.ms)
  percent: number;          // Progress percentage
}

/**
 * Filter specification object
 */
interface FilterSpec {
  filter: string;           // Filter name
  options?: string|Object;  // Filter parameters
  inputs?: string[];        // Input stream specifiers (complex filters)
  outputs?: string[];       // Output stream specifiers (complex filters)
}

Events

FfmpegCommand inherits from EventEmitter and emits the following events:

  • 'start' (commandLine) - FFmpeg process started with command line
  • 'progress' (progress: ProgressInfo) - Processing progress update
  • 'stderr' (line: string) - FFmpeg stderr output line
  • 'codecData' (data) - Input codec information detected
  • 'error' (error, stdout, stderr) - Error occurred during processing
  • 'end' (stdout, stderr) - Processing completed successfully
  • 'filenames' (filenames: string[]) - Screenshot filenames (screenshots only)
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/fluent-ffmpeg@2.1.x
Publish Source
CLI
Badge
tessl/npm-fluent-ffmpeg badge