npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quick-ffmpeg

v1.0.3

Published

The simplest down-to-earth ffmpeg wrapper for node.js

Downloads

14

Readme

FFmpeg Node.js interface quick-ffmpeg

This package is a very down-to-earth simplistic Node.js interface for the FFmpeg command line tool. FFprobe support is coming soon but is not available yet.

If there are any features missing, please let me know on the issues page!

Installation

Package

$ npm install quick-ffmpeg

FFmpeg

Make sure to install ffmpeg or use a package like ffmpeg-static in order to use this module.

Usage

Examples

You can find examples below.

Running a command

The quick-ffmpeg package returns a simple function that wraps the FFmpeg command line tool, it can be imported like so:

const qff = require(`quick-ffmpeg`)

The function ff that we just imported has one parameter which is an Object with a number of options. A very simplistic example of how it could be used is changing the format of a video from .mov to .mp4.

Note: the ff function returns a Promise

const qff = require(`quick-ffmpeg`)
const path = require(`path`)

qff.ff({
    input: path.join(__dirname, `video.mov`),
    args: `-f mp4`, // note that you should exclude the input and output arguments
    output: path.join(__dirname, `video.mp4`),
    verbose: false,
})

Advanced usage

path

The path option (and setPath function or path property) can be used to specify a path to an FFmpeg binary, which can be either in your path, your file system, or dynamically imported. Some examples are shown below

const ffPath = require(`ffmpeg-static`)

// Set the ffmpeg path as property
qff.path = `~/path/to/ffmpeg/executable`

// Set the ffmpeg path
qff.setPath(`~/path/to/ffmpeg/executable`)

// Dynamically imported FFmpeg
qff.ff({
    path: ffPath
    // for the sake of simplicity, the other parameters will be left out of the examples
})

// Example of full path being used
qff.ff({
    path: `~/path/to/ffmpeg/executable`
})

// Example assuming you have ffmpeg in your file path, useless in practice since the path defaults to ffmpeg.
qff.ff({
    path: `ffmpeg`
})

input

The input option can be more than just a file path string! Here are a few examples for the possible values of the input option.

const { readFileSync, createReadStream } = require(`fs`)
const { Readable } = require(`stream`)

// String:
qff.ff({
    input: path.join(__dirname, `video.mov`)
})

// Buffer:
qff.ff({
    input: readFileSync(`video.mov`)
})

// ReadStream
qff.ff({
    input: createReadStream(`video.mov`)
})

// ReadableStream
qff.ff({
    input: Readable.from(readFileSync(`video.mov`))
})

args

The args option can be either an array or a string containing the arguments to pass to FFmpeg. The arguments cannot include the -i argument (cannot include any input or output arguments), the input and output are handled by quick-ffmpeg. Here are a few examples of options you could pass.

Note: Do not pass quotes around a parameter value, these are normally removed by cmd before passing to the program, and will make FFmpeg fail while parsing the arguments

qff.ff({
    args: `-movflags frag_keyframe+empty_moov -filter:v framestep=2,setpts=0.5*PTS -f mp4`
})

qff.ff({
    args: `-filter:a atempo=2 -f mp3`
})

qff.ff({
    args: `-filter:v scale=w=1920:h=1080 -f avi`
})

output

The output option can also be a multitude of types (and is actually optional). Here are some examples.

Note: In the situation that you use a Buffer, WriteStream, or WritableStream as output, make sure to include the argument -movflags frag_keyframe+empty_moov if outputting to a format that is not streamable, for example mp4.

const { createWriteStream, writeFileSync } = require(`fs`)
const { Writable } = require(`stream`)

// String:
qff.ff({
    output: path.join(__dirname, `video.mp4`)
})

// WriteStream:
qff.ff({
    output: createWriteStream(`video.mp4`)
})

// WritableStream:
const chunks = []
qff.ff({
    output: Writable({
        write (chunk, encoding, callback) {
            chunks.push(chunk)
            callback()
        }
    })
})

// Excluded
let bfr = qff.ff({})
writeFileSync(`video.mp4`, bfr)

verbosity

The verbose and verboseCallback options can be used to retrieve or log ffmpeg output (verbose defaults to false). Some examples are below.

Note: output is passed to the verboseCallback in form of Buffers, not strings.

// Logs all ffmpeg output to the console
qff.ff({
    verbose: true
})

// Saves all ffmpeg output to a text file
const output = [];
(async () => {
    const command = await qff.ff({
        input: path.join(__dirname, `video.mov`),
        args: `-f mp4`,
        output: path.join(__dirname, `video.mp4`),
        verbose: true,
        verboseCallback: (data) => output.push(data.toString())
    }).then(() => true).catch(console.log)

    if (command) writeFileSync(`log.txt`, output.join(`\n`))
})()

Contributions

Contributions are always welcome! Feel free to send pull requests to correct/improve/add things!

License

The license is to be found in the LICENSE file.