All Projects → FedericoCarboni → eloquent-ffmpeg

FedericoCarboni / eloquent-ffmpeg

Licence: MIT License
High-level API for FFmpeg's Command Line Tools

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to eloquent-ffmpeg

video-audio-tools
To process/edit video and audio with Python+FFmpeg. [简单实用] 基于Python+FFmpeg的视频和音频的处理/剪辑。
Stars: ✭ 164 (+130.99%)
Mutual labels:  ffmpeg, video-processing, audio-processing
DuME
A fast, versatile, easy-to-use and cross-platform Media Encoder based on FFmpeg
Stars: ✭ 66 (-7.04%)
Mutual labels:  ffmpeg, video-processing, audio-processing
Mlt
MLT Multimedia Framework
Stars: ✭ 836 (+1077.46%)
Mutual labels:  ffmpeg, video-processing, audio-processing
ffmpeg-progressbar-cli
A colored progress bar for FFmpeg.
Stars: ✭ 140 (+97.18%)
Mutual labels:  ffmpeg, ffmpeg-wrapper
Lintel
A Python module to decode video frames directly, using the FFmpeg C API.
Stars: ✭ 240 (+238.03%)
Mutual labels:  ffmpeg, video-processing
VideoProcessingLibrary
The easiest library for video processing
Stars: ✭ 52 (-26.76%)
Mutual labels:  video-processing, ffmpeg-wrapper
Vidgear
A High-performance cross-platform Video Processing Python framework powerpacked with unique trailblazing features 🔥
Stars: ✭ 2,048 (+2784.51%)
Mutual labels:  ffmpeg, video-processing
old-audiosync
First implementation of the audio synchronization feature for Vidify, now obsolete
Stars: ✭ 16 (-77.46%)
Mutual labels:  ffmpeg, audio-processing
ffcvt
ffmpeg convert wrapper tool
Stars: ✭ 32 (-54.93%)
Mutual labels:  video-processing, audio-processing
AudioConverter
Audio Conversion CLI
Stars: ✭ 17 (-76.06%)
Mutual labels:  conversion, audio-processing
Super-Stitch
一款视频超级拼接软件
Stars: ✭ 28 (-60.56%)
Mutual labels:  ffmpeg, video-processing
video-summarizer
Summarizes videos into much shorter videos. Ideal for long lecture videos.
Stars: ✭ 92 (+29.58%)
Mutual labels:  ffmpeg, video-processing
looking-to-listen-at-cocktail-party
Looking to listen at cocktail party
Stars: ✭ 33 (-53.52%)
Mutual labels:  video-processing, audio-processing
Online Video Editor
API based Online Video Editing using FFMPEG & NodeJs for Backend Editing
Stars: ✭ 176 (+147.89%)
Mutual labels:  ffmpeg, video-processing
Prism Media
Easily transcode media using Node.js 🎶
Stars: ✭ 136 (+91.55%)
Mutual labels:  ffmpeg, audio-processing
FFCreatorLite
一个基于node.js的轻量极速短视频加工库 A lightweight and fast short video processing library based on node.js
Stars: ✭ 155 (+118.31%)
Mutual labels:  ffmpeg, video-processing
lecture-demos
Demonstrations for the interactive exploration of selected core concepts of audio, image and video processing as well as related topics
Stars: ✭ 12 (-83.1%)
Mutual labels:  video-processing, audio-processing
Ffscreencast
ffscreencast - ffmpeg screencast/desktop-recording with video overlay and multi monitor support
Stars: ✭ 1,625 (+2188.73%)
Mutual labels:  ffmpeg, ffmpeg-wrapper
Fwf
HTML video editor with FFmpeg
Stars: ✭ 128 (+80.28%)
Mutual labels:  ffmpeg, video-processing
reisen
A simple library to extract video and audio frames from media containers (based on libav).
Stars: ✭ 41 (-42.25%)
Mutual labels:  ffmpeg, ffmpeg-wrapper

Eloquent FFmpeg

Language grade: JavaScript Known Vulnerabilities tests Codecov Coverage FOSSA Status

Eloquent FFmpeg simplifies interactions with FFmpeg's command line tools into a simple yet powerful API. This library is fully typed, so in editors such as VS Code, intellisense should help you get started. You may also want to view the API documentation or examples/.

If something is missing or doesn't feel right, feel free to open an issue or a pull request to change it. This library is still in a very early stage, but there shouldn't be any major breaking changes.

Only NodeJS 10.x or higher is supported

Prerequisites

Eloquent FFmpeg requires a recent version of FFmpeg to be installed. Make sure that ffmpeg and ffprobe executables are in PATH, or use the options ffmpegPath and ffprobePath.

GitHub Actions

To install FFmpeg on a GitHub Actions' runner use FedericoCarboni/setup-ffmpeg.

Usage

Since most of Eloquent FFmpeg's methods are asynchronous it is advised to use async-await to improve readability.

A simple example could use the following:

// Create a new command
const cmd = ffmpeg({
  // Include any options here...
});

// Select input(s)
cmd.input('input.mkv');
// ... and output(s)
cmd.output('output.mp4');

// Spawn ffmpeg as a child process
const proc = await cmd.spawn();
// Wait for the conversion to complete
await proc.complete();

Streams

Streams can be used as input sources and output destinations, there is no hard limit on how many streams can be used. Pass Node.js streams directly to FFmpegCommand.input() and FFmpegCommand.output().

Example using Node.js' fs module.

const cmd = ffmpeg();
cmd.input(fs.createReadStream('input.mkv'));
// The same output will be written to two destinations.
cmd.output(fs.createWriteStream('dest1.webm'), 'dest2.webm')
// When using streams the format must be explicitly specified
// because it can't be inferred from the file extension.
  .format('webm');

const proc = await cmd.spawn();
await proc.complete();

Note: Some formats require inputs and/or outputs to be seekable which means that they cannot be used with streams, notable example being MP4. Some other formats require a special format name to be explicitly set, for example to use streams for GIF files the input format must be gif_pipe.

See FFmpegCommand.input() and FFmpegCommand.output()

Concatenate Inputs

To concatenate inputs use FFmpegCommand.concat(), at the moment it is still unstable.

const cmd = ffmpeg();
cmd.concat(['file:input1.mkv', 'file:input2.mkv']);
cmd.output('output.mkv');

const proc = await cmd.spawn();
await proc.complete();

Note: When passing inputs to FFmpegCommand.concat() the protocol must be explicitly specified: file: for example; streams are handled automatically. Sometimes it may be necessary to explicitly enable certain protocols.

const cmd = ffmpeg();
cmd.concat(['file:input1.mkv', 'https://example.com/input2.mkv'], {
  protocols: ['file', 'tcp', 'tls', 'http', 'https'],
});
cmd.output('output.mkv');

const proc = await cmd.spawn();
await proc.complete();

See FFmpegCommand.concat() and ConcatOptions.

Input & Output Options

Eloquent FFmpeg exposes a few methods which act as a shortcut to set a few options. See FFmpegInput and FFmpegOutput

const cmd = ffmpeg();
cmd.input('input.mp4')
  .format('mp4');
cmd.output('output.mkv')
  .audioCodec('aac');

To set input and output options their .args() method can also be used.

const cmd = ffmpeg();
cmd.input('input.mp4')
  .args('-format', 'mp4');
cmd.output('output.mkv')
  .args('-codec:a', 'aac');

Logging and Debugging

For debbugging, FFmpegCommand.spawn()'s options accept logger and report.

The report option dumps the full command line arguments and logs to the specified file or, when not specified, FFmpeg will create a file named ffmpeg-YYYYMMDD-HHMMSS.log in its current directory. When the log level is not specified FFmpeg defaults to LogLevel.Debug.

See -loglevel and -report in FFmpeg's docs.

const cmd = ffmpeg({
  level: LogLevel.Warning,
});
cmd.input('input.mkv');
cmd.output('output.mp4');

const proc = await cmd.spawn({
  // Enable logger and report when not in production mode.
  logger: process.env.NODE_ENV !== 'production' && {
    warning: (message) => {
      console.warn('FFmpeg warning:', message);
    },
  },
  report: process.env.NODE_ENV !== 'production' && {
    file: 'ffmpeg-123.log',
    level: LogLevel.Debug,
  },
});
await proc.complete();

Controlling the conversion

Make sure to check the API documentation for FFmpegProcess.

Monitor progress

To receive real-time updates on the conversion's progress, use the FFmpegProcess.progress() method. It returns an async generator of Progress.

const cmd = ffmpeg();
cmd.input('input.mkv');
cmd.output('output.mp4');
const proc = await cmd.spawn();
for await (const { speed, time } of proc.progress()) {
  console.log(`Converting @ ${speed}x – ${time}/${TOTAL_TIME}`);
}
// NOTE: The progress generator will return when ffmpeg writes a
// `progress=end` line, which signals the end of progress updates,
// not the conversion's completion.
// Use proc.complete() to wait for completion.
await proc.complete();
console.log('Hooray! Conversion complete!');

To use Node.js' streams, FFmpegProcess.progress() can be turned into a Node.js readable stream using Readable.from().

const cmd = ffmpeg();
cmd.input('input.mkv');
cmd.output('output.mp4');
const proc = await cmd.spawn();
const progress = Readable.from(proc.progress());
progress.on('data', ({ speed, time }) => {
  console.log(`Converting @ ${speed}x – ${time}/${TOTAL_TIME}`);
});
progress.on('end', () => {
  // NOTE: The progress stream will end when ffmpeg writes a
  // `progress=end` line, which signals the end of progress
  // updates, not the conversion's completion.
  console.log('No more progress updates');
});
// Use proc.complete() to wait for completion.
await proc.complete();
console.log('Hooray! Conversion complete!');

Tracking progress as a percentage: To get a percentage from the progress the total duration of the media must be known, this is very easy if the duration is not modified.

Probe the input file and calculate the percentage by dividing the current time by the duration and multiplying by 100.

const cmd = ffmpeg();
const input = cmd.input('input.mkv');
const info = await input.probe();
cmd.output('video.mp4');
const proc = await cmd.spawn();
for await (const { speed, time } of proc.progress()) {
  console.log(`Converting @ ${speed}x – ${time / info.duration * 100}%`);
}
await proc.complete();
console.log('Hooray! Conversion complete!');

Pause and Resume

The conversion can be paused and resumed using FFmpegProcess.pause() and FFmpegProcess.resume(). Both methods are synchronous, they return true upon success, false otherwise.

Note: On Windows this requires the optional dependency ntsuspend to be installed.

const cmd = ffmpeg();
cmd.input('input.mkv');
cmd.output('output.mp4');
const proc = await cmd.spawn();
// Pause the conversion
proc.pause();
// Resume...
proc.resume();

await proc.complete();

Abort

The conversion can be terminated early using FFmpegProcess.abort(), this gracefully interrupts the conversion allowing FFmpeg to end the file correctly. The method is asynchronous.

Note: abort() resolves when FFmpeg exits, but it doesn't guarantee that it will exit successfully, any possible errors should be handled explicitly.

const cmd = ffmpeg();
cmd.input('input.mkv');
cmd.output('output.mp4');
const proc = await cmd.spawn();
await proc.abort();

Errors

FFmpeg exited with code x

FFmpeg exited with a non-zero status code, which means that the conversion failed. This typically occurs because of a corrupt input or a wrong configuration. See Logging and Debugging.

FFmpeg exited prematurely

FFmpeg exited without a status code. This typically means that the conversion was forcefully terminated (or that an error occurred in a system call). See Logging and Debugging.

Cannot import ntsuspend

This error is likely caused by a corrupt or missing installation of ntsuspend. ntsuspend is required to pause and resume the FFmpeg child process on Windows. Try to uninstall and reinstall ntsuspend, and if you experience further problems open a new issue to get help.

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].