This package will generate n numbers of thumbnails at different positions in a given video file.

Overview

The smallest library to generate video thumbnails on client side.

About

Generate n numbers of Image thumbnails of a video file.

!Live Demo


code sandbox example

video-thumbnail-generate.mp4

This package can be used with any JS framework or in vanila js.

NPM

Purpose?

This module will generate n numbers of image thumbnails of a given video file.

By default the thumbnail's file format will be the base64.

Usage

generateVideoThumbnails(selectedFile, numberOfThumbnails)

Async/Await (Typescript & ES7)

generateVideoThumbnails(videoFile, numberOfThumbnails).then((thumbnailArray) => {
    // output will be arry of base64 Images
    // example - ["img1", "imgN"]

    // @todo - implement your logic here
}).catch((err) => {
    console.error(err);
})

Using promises and dynamic Import (Html5)

// please change the location of index.js as needed

import("./index.js").then((res) => {
    res.generateVideoThumbnails(videoFile, noThumb).then((thumbArray) => {
        thumbArray.map((item) => {
            // type of item is base64 image

            // @todo - your logic here
        })              
    })
});

Examples

From File Input

complete working example is in the index.html file or you can visit the demo link

 let video = document.getElementById("video");
        let inputFile = document.getElementById("inputfile");
        let numberInput = document.getElementById("numberofthumbnails");
        let numberWrapper = document.getElementById("numberWrapper");
        let buttonWrapper = document.getElementById("buttonWrapper");
        let thumbButton = document.getElementById("generatethumbnails");
        let thumbnaislWrapper = document.getElementById("thumbnails");
        let loader = document.getElementById("loader");
        let selectedFile = "";

        inputFile.addEventListener("change", function (e) {
            if (e.target.files?.length) {
                selectedFile = e.target.files[0];

                var source = document.createElement('source');
                import("./index.js").then((res) => {
                    res.importFileandPreview(e.target.files[0]).then((url) => {

                        source.setAttribute('src', url);
                        source.setAttribute('type', e.target.files[0]?.type);

                        res.generateVideoThumbnails(e.target.files[0], 1).then((thumbnails) => {
                            // video operations
                            // video.setAttribute("poster", thumbnails[1])
                            // video.setAttribute("src", url)
                            video.style.width = "auto";
                            video.style.height = "auto"
                            video.style.transform = "scale(1)"
                        })
                        // numberInput
                        numberWrapper.style.display = "block";
                        buttonWrapper.style.display = "block";
                        video.style.transform = "scale(1)"
                        video.innerHTML = "";
                        video.appendChild(source);
                    });
                })
            }
        });
        thumbButton.addEventListener("click", function () {
            thumbnaislWrapper.innerHTML = "";
            loader.style.display = "block";
            import("./index.js").then((res) => {
                res.generateVideoThumbnails(selectedFile, parseInt(numberInput.value)).then((thumbArray) => {
                    let thumbnailsImg = thumbArray.map((item) => {
                        let img = document.createElement('img');
                        img.src = item;
                        img.alt = "";
                        img.style.width = "200px";
                        img.style.objectFit = "cover";
                        img.style.margin = "10px";
                        img.style.cursor = "pointer";
                        img.addEventListener("click", function () {
                            video.setAttribute("poster", item);
                        })
                        return img;
                    })
                    thumbnaislWrapper.innerHTML = "";
                    loader.style.display = "none";
                    thumbnailsImg.forEach((item) => {
                        thumbnaislWrapper.appendChild(item);
                    })
                })
            });

        })

Your contributions are more than welcome 😀


ROADMAP đŸ—ș

  1. Lib roubstness and accuracy increment.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Comments
  • New callback for async generation

    New callback for async generation

    Added new callback option that will be called at each thumb generated. This allow users to have large videos and large number of thumbs without breaking the UI.

    feature 
    opened by quantodaniel 2
  • Generate thumbnails asynchronously.

    Generate thumbnails asynchronously.

    Added a new callback option that will be called at each thumb generated. This allows users to have large videos and a large number of thumbs without breaking the UI.

    async generation 4.webm

    feature 
    opened by Rajesh-Royal 1
  • thumbnails not getting generated for videos created by iphone 12 or higher mobile devices

    thumbnails not getting generated for videos created by iphone 12 or higher mobile devices

    I have a case scenario in a website where i have to upload a video a get a thumbnail of that video , the library seems to work perfectly for the web as well as for video made by android devices . But for the videos created by iphone 11 pro, 11 proMax and 12 , and higher devices , black thumbnails are getting generated , couldn't seem to understand this issue , so creating this issue , I seem to have run out for options now. Please check this issue.

    opened by techdevelopers08 1
  • Cannot generate thumbnails from a Url.

    Cannot generate thumbnails from a Url.

    A user is not able to generate thumbnails from a video file URL.

    Error:

    Access to video at 'https://xyz.com/file_example_MP4_640_3MG.mp4' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    

    Acceptance criteria It should generate thumbnails from a video file URL

    bug 
    opened by Rajesh-Royal 0
  • Error: remove the loaders on error:

    Error: remove the loaders on error:

    While generating thumbnails from a video file or from a URL if an error occurs to access the file or from a remote origin the loaders keep loading and the error state is not shown.

    expected: The loaders should be replaced with the error details.

    Preview:

    image

    bug 
    opened by Rajesh-Royal 0
Releases(1.0.0)
Owner
Rajesh Royal
Your code's boyfriend                              Have đŸ”„ to learn new things, do experiments, fix đŸ•·ïž, and write about it.
Rajesh Royal
BookStore is a website that allows a given user to view a list of books, to add a new book and remove a given book.

Project Name : BookStore CMS BookStore is a website that allows a given user to view a list of books, to add a new book and remove a given book. In or

Chris Siku 10 Aug 22, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
A self-hosted Thumbnail generator/finder which creates thumbnails based on folder names and google search results.

Thumba A self hosted Thumbnail generator/finder which creates thumbnails based on folder names and google search results. Description This project use

Norbert TakĂĄcs 20 Dec 15, 2022
Cross-browser plugin to remove addictive features on YouTube like thumbnails, comments, previews and more...

ZenTube Installation Features Remove some (more) elements from Youtube to make it less addictive. Mix and match between the following options: Hide or

inversepolarity 57 Dec 17, 2022
Twitter bot to find what song is playing in a given uploaded twitter video.

what-song-is-this Twitter bot to find what song is playing in a given uploaded twitter video. How to setup. yarn install How to run. via npm script ya

Akinwande Akinboluwarin 17 Dec 11, 2022
Generate prime numbers from pictures!

Pictoprime This is a program used to generate prime numbers from pictures. Dependencies Ensure you have the following dependencies: Node.js (16+ suppo

Jesse Mitchell 276 Dec 27, 2022
A small JavaScript library to generate YouTube-like ids from numbers.

Hashids is small JavaScript library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user: htt

Bazyli BrzĂłska 3.9k Dec 30, 2022
Script to fetch all NFT owners using moralis API. This script output is a data.txt file containing all owner addresses of a given NFT and their balances.

?? Moralis NFT Snapshot Moralis NFT API will only return 500 itens at a time when its is called. For that reason, a simple logic is needed to fetch al

Phill Menezes 6 Jun 23, 2022
A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ?? A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Ben Smith 21 Jun 20, 2022
Serve file server with single zip file as file system in Deno.

zipland Serve file server with one-single zip file in Deno. Support zip just zip32 with deflated or uncompressed serving plaintext deflate Examples Yo

Yongwook Choi 18 Nov 2, 2022
Feel free to create new file, don't hesitate to pull your code, the most important thing is that the file name here must match your nickname so that file does not conflict with other people.

Hacktoberfest Indonesia Apa Itu Hacktoberfest ? Hacktoberfest adalah acara tahunan yang bertujuan untuk mendorong berkontribusi kedalam ekosistem open

Juan Daniel 5 Dec 15, 2022
This repository contains different infrastructure components that are used in different projects here at NaN Labs.

Infrastructure Reference Changelog | Contributing This repository contains different infrastructure components that are used in different projects her

NaN Labs 10 Dec 15, 2022
Incredible drastically simplifies creation of developer video content. It offers a unified workflow to storyboard, record, collaborate and produce the video.

?? Introduction Incredible drastically simplifies creation of developer video content. It offers a unified workflow to storyboard, record, collaborate

Incredible 113 Dec 6, 2022
A simple cli-app that allows you to divide a YouTube video into multiple separate videos base on a video's time stamps. Powered by pkg and yt-scissors library.

YouTube-Scissors CLI A simple CLI app that allows you to divide a YouTube video into multiple separate videos base on a video's time stamps. This proj

Gabe 23 Nov 8, 2022
This package enables you to mount your Remix app at a different path than root

Remix Mount Routes This package enables you to mount your Remix app at a different path than root. ?? Installation > npm install -D remix-mount-routes

Kiliman 26 Dec 17, 2022
This package generates a unique ID/String for different browsers. Like chrome, Firefox and any other browsers which supports canvas and audio Fingerprinting.

Broprint.js The world's easiest, smallest and powerful visitor identifier for browsers. This package generates a unique ID/String for different browse

Rajesh Royal 68 Dec 25, 2022
Generate short video game music, automatically, endlessly.

short-VGM-generator (DEMO) Generate short video game music, automatically, endlessly. It is powered by machine learning with magenta.js HOW TO PLAY Pr

ABA Games 8 Oct 28, 2022
đŸ€–â€An action that fetches the list of malicious domains on Discord in different providers and creates/updates a JSON file with them from time to time.

Discord Guardian Action ??  This action fetches the list of malicious domains on Discord in different providers and creates/updates a JSON file with t

Dalton Menezes 7 Nov 30, 2022