Code Monkey home page Code Monkey logo

thumbsupply's Introduction

thumbsupply

Asynchronous Node.js module to create, cache and fetch thumbnails from videos. It uses ffmpeg to generate thumbnails and ES6 Promise.

The API is more reliable now and is unlikely to have major changes before stable release.

Healthy criticisms, feature requests and issues are welcome.

NOTE: Since v0.2, the module no longer maintains thumbnails separately for each application. This behavior is intended to improve the performance and utilize caching as far as possible.

Installation

npm install thumbsupply

Usage

Generating Thumbnails

The resolved promise gives filepath of the generated thumbnail. In case of modifications to be performed on the generated thumbnail, it's recommended to work on a copy.

Using generateThumbnail() method by default enables caching to speeden up the process.

const thumbsupply = require('thumbsupply');

thumbsupply.generateThumbnail('some-video.mp4')
    .then(thumb => {
        // serve thumbnail
    })

It accepts options to control timestamp and size of the thumbnail. The forceCreate option can be used to generate the thumbnail every time. Mimetype of the file can be specified using mimetype option. It overrides mimetype derived from the file extension and can be used for cases where such derivation is not possible. cacheDir allows configuring the directory to store the thumbnail cache. Unless there is an explicit need, it is good to use shared cache.

const thumbsupply = require('thumbsupply');

thumbsupply.generateThumbnail('some-video.mp4', {
    size: thumbsupply.ThumbSize.MEDIUM, // or ThumbSize.LARGE
    timestamp: "10%", // or `30` for 30 seconds
    forceCreate: true,
    cacheDir: "~/myapp/cache",
    mimetype: "video/mp4"
})

NOTE: Thumbnails which are older than the video get expired automatically.

Look up Thumbnails

Instead of creating a thumbnail, sometimes you may need to get the thumbnail if it exists.

const thumbsupply = require('thumbsupply');

thumbsupply.lookupThumbnail('some-video.mp4')
    .then(thumb => {
        // serve thumbnail
    })
    .catch(err => {
        // thumbnail doesn't exist
    });

Features on the way

thumbsupply will soon be supporting music, pictures and so on. The architecture required is already shipped.

Developers can experiment with some of the non public API's to create thumbnail suppliers supporting new formats. Documentation on how to do that will be released with the production version.

Limitations

  • Thumbnail sizes may get rounded off to next even number. Find more information here

thumbsupply's People

Contributors

ryanafrish7 avatar kj800x avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.