simple-thumbnail
A minimal library that produces thumbnails from images and videos using FFmpeg.
Installation
$ npm install simple-thumbnail --save
Usage
const fs = const genThumbnail = // promise // async/await { try await console catch err console } // genThumbnail also supports piping to write streams, so you can do this with Express!app // duplex streamsfs
Getting FFmpeg
For those who don't have FFmpeg installed, there's an NPM package that installs it for you: https://www.npmjs.com/package/ffmpeg-static
const ffmpeg = const genThumbnail = { await console}
API
genThumbnail(input, output, size, [config])
Returns of a Promise
which resolves on thumbnail creation, or a stream.Duplex
(see below).
input
Type: String | stream.Readable | Null
The URL, file path, or read-stream of an image or video. If both the input and output are null, then genThumbnail
will return a stream.Duplex
.
output
Type: String | stream.Writable | Null
The file path of the generated thumbnail, a write-stream, or null. If null, genThumbnail
will resolve to a read-stream that you can pipe somewhere. If you're specifying a file path, make sure the directories exist.
size
Type: String
The dimensions of the generated thumbnail. The size
argument may have one of the following formats:
150x100
: set a fixed output size.150x?
: set a fixed width and compute the height automatically.?x100
: set a fixed height and compute the width automatically.50%
: rescale both width and height to given percentage.
config
Type: Object
A configuration object, see details below.
config.path
Type: String
The path of the ffmpeg
binary. If omitted, the path will be set to the FFMPEG_PATH
environment variable. If the environment variable is not set, ffmpeg
will be invoked directly (ie. ffmpeg [...]
).
config.seek
Type: String
Seeks the video to the provided time. The time must be in the following form: hh:mm:ss[.ms]
, eg. 00:00:42.23
. If omitted, the video time will be set to 00:00:00
(ie. the first frame).
config.args
Type: Array<String>
FFmpeg arguments that override the synthetic arguments created by simple-thumbnail
; you'll likely need to pass include your own -i
flag, -y
flag, etc.
Contributors
Philip Scott 💻 ⚠️ 📖 |
cmd430 💻 🤔 |
Andre-John Mas 💻 🐛 |
---|
This project follows the all-contributors specification.
Contributions of any kind are welcome!
Contributing
See CONTRIBUTING.md.