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

ffmpeg-generate-video-preview

v1.0.3

Published

Generates an attractive image strip or GIF preview from a video.

Downloads

129

Readme

ffmpeg-generate-video-preview

Generates an attractive image strip or GIF preview from a video.

NPM Build Status JavaScript Style Guide


Example 6x5 image strip preview (video credit Big Buck Bunny).

Image Strip Example

generate-video-preview big-buck-bunny.avi output.jpg --width 160 --rows 5 --cols 6

Example 6x5 image strip preview with black padding and margin.

Image Strip Example with Padding

generate-video-preview big-buck-bunny.avi output.jpg --width 160 --rows 5 --cols 6 --padding 4 --margin 4

Example gif preview with 30 frames at 4 fps.

GIF Example

generate-video-preview big-buck-bunny.avi output.gif --width 320 --num-frames 30 --gif-fps 4

Install

npm install --save ffmpeg-generate-video-preview

# or if you want to use the CLI
npm install -g ffmpeg-generate-video-preview

This module requires ffmpeg to be installed.

If you want to generate GIFs, you must also install gifski. On Mac OS, you can run

brew install gifski

CLI

  Usage: generate-video-preview [options] <input> <output>

  Options:

    -V, --version                 output the version number
    -w, --width <width>           frame width
    -h, --height <height>         frame height
    -q, --quality <n>             frame image quality
    -n, --num-frames <n>          number of frames to capture
    -p, --num-frames-percent <n>  number of frames to capture as % of overall frames
    -P, --padding <n>             image strip tile padding (default: 0)
    -M, --margin <n>              image strip border margin (default: 0)
    -r, --rows <n>                image strip number of rows
    -c, --cols <n>                image strip number of cols
    -C, --color <color>           image strip background color (default: Black)
    -f, --gif-fps <n>             gifski fps (default: 10)
    -Q, --gif-quality <n>         gifski quality (default: 80)
    -F, --gif-fast                enable gifski fast mode
    -h, --help                    output usage information

Usage

const generatePreview = require('ffmpeg-generate-video-preview')

const metadata = await generatePreview({
  input: 'media/1.mp4',
  output: 'preview.gif',
  width: 128
})

console.log(metadata)
// => {
//   output: 'preview.gif',
//   numFrames: 5,
//   width: 128,
//   height: 72
// }

API

generatePreview(options)

Generates a preview image strip or GIF from a video file. Returns a Promise for when the output file(s) have been written.

Note that some options only target image strips, and some only target GIFs.

options

input

Type: String

Path or URL to a video file.

output

Type: String

Path to a jpg, png, or gif file to output. If output is a gif, then a GIF will be created via gifski; otherwise, an image strip will be generated according to rows and cols.

width

Type: Number

Scales the input to the specified width. If height isn't specified, the aspect ratio of the input will be preserved.

height

Type: Number

Scales the input to the specified height. If width isn't specified, the aspect ratio of the input will be preserved.

quality

Type: Number Default: 2

If exporting a jpeg image, the quality from 1-31 with 31 being the worst quality (source).

If exporting a GIF, this will dictate the image quality of the intermediate frames, not the final output gif quality. Also see gifski.quality.

numFrames

Type: Number

Specify an exact number of frames to capture. Note that if you specify rows and cols for image strips, this value will be overridden.

numFramesPercent

Type: Number Default: 0.05

Specify a percentage of frames to capture as a floating point number between 0 and 1. Defaults to 5%. Note that if you specify numFrames or rows and cols for image stripsgifs, this value will be overridden.

rows

Type: Number Default: 1 (Image Strips Only)

Number of rows to generate in an image strip. See the ffmpeg tile filter for details.

Defaults to one long horizontal image strip with one row.

cols

Type: Number (Image Strips Only)

Number of columns to generate in an image strip. See the ffmpeg tile filter for details.

Note that if cols isn't specified, it will be inferred. Also note that specifying both rows and cols is the easiest way to specify the number of frames to generate in an image strip.

padding

Type: Number Default: 0 (Image Strips Only)

Adds a padding between each image in an image strip. See the ffmpeg tile filter for details.

margin

Type: Number Default: 0 (Image Strips Only)

Adds an outer margin to an image strip. See the ffmpeg tile filter for details.

color

Type: String Default: Black (Image Strips Only)

Background color for unused areas of the image strip. May be any valid ffmpeg color syntax string.

gifski

Type: Object Default: { fps: 10, quality: 80, fast: false } (GIFs Only)

Gifski customization options. Run gifski -h for details.

log

Type: Function Default: noop

Optional function to log the underlying ffmpeg and gifski command(s). You may, for example, use console.log

Related

License

MIT © Travis Fischer