1.0.0 • Published 8 months ago

like-ffmpeg v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

like-ffmpeg

Simple processing of audio and video using FFmpeg

npm i like-ffmpeg

Usage

const FFmpeg = require('like-ffmpeg')

// Generate random files
const video = ffmpeg.randomVideo('./video.mp4')
const audio = ffmpeg.randomAudio('./audio.mp3')

await video.done()
await audio.done()

// Merge (video + audio)
const inputs = ['./video.mp4', './audio.mp3']
const output = './merge.mp4'

await ffmpeg.merge(inputs, output).done()

// Cut
await ffmpeg.cut('./merge.mp4', { start: 5, end: 10 }).done()

// Destroy all FFmpeg processes if any
await ffmpeg.close()

API

ffmpeg = new FFmpeg()

Creates a FFmpeg instance.

await ffmpeg.close()

Destroy all ff running processes, and closes the FFmpeg instance.

ff = ffmpeg.exec(args)

Executes a custom command. Args be like ['-f', 'lavfi', '-i', ...].

All of the ff instances below behave like this:

  • Wait until complete: await ff.done()
  • Destroy the process: await ff.close()

ff = ffmpeg.merge(inputs, output, [options])

Merge inputs into a single output.

The default options allows merge([video, audio], out) in that order.

Otherwise, set the correct mapping if you pass inputs in different order.

Options:

{
  // Defaults
  codec: 'copy',
  map: [{ input: 0, type: 'v', index: 0 }, { input: 1, type: 'a', index: 0 }]
}

ff = ffmpeg.cut(input, output, [options])

Cut input into a new output.

Options:

{
  start: 0,
  end, // One of "end" or "length" is required
  length: end - start
}

ff = ffmpeg.randomVideo(filename, [options])

Generate a random video with RGB colors.

Options:

{
  length: 30
}

ff = ffmpeg.randomAudio(filename, [options])

Generate a random audio with sample frecuencies.

Options:

{
  length: 30
}

License

MIT

1.0.0

8 months ago