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

Overview

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. Generate thumbnails From Uri
  2. Generate thumbnails From Base64
  3. Add typescript support. [done]
  4. Add more customization options.

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
Video.js - open source HTML5 & Flash video player

Video.js - HTML5 Video Player Video.js is a web video player built from the ground up for an HTML5 world. It supports HTML5 video and Media Source Ext

Video.js 34.8k Jan 5, 2023
A Node JS Express/Serverless demo application that creates a slideshow video using the Pexels image library and Shotstack video editing API.

Shotstack Pexels Slideshow Video Demo This project demonstrates how to use the Shotstack cloud video editing API to create a video using an HTML form

Shotstack 25 Dec 9, 2022
A Chrome extension to help you inspect Mp4 video content and find irregularities in video streams.

MP4Inspector A Chrome extension to help you inspect Mp4 video content and find irregularities in video streams. Installation In chrome navigate to chr

Bitmovin 48 Nov 28, 2022
A video media file convertor using FFmpeg's web assembly port

A video media file convertor using FFmpeg's web assembly port

Atharva Marathe 2 Aug 25, 2022
A proof-of-ownership Discord bot for SNIP-721 tokens on the Secret Network. Verified owners are given specified roles.

SNIP-721 Proof-of-Ownership Discord Bot A proof-of-ownership Discord bot for SNIP-721 tokens on the Secret Network. Verified owners are given specifie

Kevin K 9 Nov 10, 2022
A NodeJS package for voice channel interactions on Revolt. This package lets you join voice channels, play music and more!

Revoice.js - A Voice Module for Revolt This package is still in developement and lacks many features. You still are able to play sound to a voice chan

ShadowLp174 13 Dec 25, 2022
A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.

SoundJS SoundJS is a library to make working with audio on the web easier. It provides a consistent API for playing audio in different browsers, inclu

CreateJS 4.3k Dec 31, 2022
It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with buttons. It can play youtube songs, playlists. This bot code was made by Supreme#2401. It uses djs V12

Lofi-Radio-Music-Bot It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with butt

Diwas Atreya 89 Jan 2, 2023
A movie critic site allowing users to browse different selection of movie titles, tv shows, pod cast and more

A movie critic site allowing users to browse different selection of movie titles, tv shows, pod cast and more! A user can click on Whats a Potatoe Meter? to access the comments page a leave a rating on their favorite title from the list we have on the dropdown.

Aaron Lu 3 Mar 22, 2022
Kanna is a Discord bot written in Javascript developed by Mirabellier just for fun. 🍄 Containing over 100+ commands from different categories (soon). 🌼

Kanna Kanna is a Discord bot written in Javascript developed by Mirabellier just for fun. ?? Containing over 100+ commands from different categories (

Mira 8 Dec 15, 2022
Enables

HTML5 video made easy All it takes is a single line of code to make HTML5 video and audio tags work in all major browsers. How to enable video and aud

Dave Hall 1.3k Dec 17, 2022
The HTML5 video player for the web

Flowplayer website | demos | docs For the impatient Download Flowplayer Unzip Drop the folder under your server Minimal setup <!DOCTYPE html> <head>

Flowplayer 1.9k Dec 30, 2022
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Dec 27, 2022
A lightweight, easy-to-use jQuery plugin for fluid width video embeds.

Introducing FitVids.js A lightweight, easy-to-use jQuery plugin for fluid width video embeds. FitVids automates the Intrinsic Ratio Method by Thierry

Dave Rupert 4.8k Dec 24, 2022
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Jan 8, 2023
A web video player built for the HTML5 world using React library.

video-react Video.React is a web video player built from the ground up for an HTML5 world using React library. Installation Install video-react and pe

null 2.4k Jan 6, 2023
Tonton video tutorial di YouTube saya untuk cara penginstalan & apabila kurang mengerti bisa hubungi saya di WhatsApp 🐣Klik link di bawah untuk tutorial penginstalan di heroku

BOTZ10 LAST Termux • Heroku • Session Setting • Thanks TERMUX Git clone this repo > git clone https://github.com/zeeoneofc/BOTZ10a.git > cd BOTZ10a >

zeeone 17 Dec 23, 2021
🎥 ⬇️ 📦 - Public Video URLs.

WatchVideoByLink WatchVideoByLink is a web-app that allows you to watch, download and organize public video URLs. Why WatchVideoByLink? | Installation

Mohamed Bakoush 142 Dec 12, 2022
Modern browsers already had a vivid player for video

Modern browsers already had a vivid player for video. However, web developers and designers still want to custom their own style player for different situations. Sounds like web component will do a lot favor for this purpose. With <msc-ez-video /> support, customize control panel will become a piece of cake. <msc-ez-video /> adopts CSS custom properties, developers could style them as they want.

Paul 1 Dec 29, 2021