Coder Social home page Coder Social logo

gumball12 / generate-video-dumbnail Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.68 MB

iOS Safari has issues generating video thumbnails.

Home Page: https://shj.rip/article/how-to-generate-video-thumbnails-correctly-in-ios-safari.html

License: MIT License

TypeScript 100.00%
ios safari video-thumbnail generate-video-thumbnail generate-video-thumbnail-on-ios-safari

generate-video-dumbnail's Introduction

generate-video-dumbnail

npm bundle size NPM Downloads jsDelivr hits (npm) NPM Version

Video thumbnail generator for modern browsers. Supports Windows, macOS, AOS, and the ever-pesky iOS Safari(14+).

Blog post: How to Generate Video Thumbnails Correctly in iOS Safari ๐Ÿ”

Online Demo

Want to contribute? Please read the CONTRIBUTING.md.

Installation

npm install generate-video-dumbnail
yarn add generate-video-dumbnail
pnpm add generate-video-dumbnail

CDN

<script src="https://cdn.jsdelivr.net/npm/generate-video-dumbnail/dist/index.iife.js"></script>
<script>
  generateVideoThumbnail.generateVideoThumbnail(/* ... */);
</script>

Usage

import { generateVideoThumbnail } from 'generate-video-dumbnail';

const MY_VIDEO_URL = 'https://example.com/video.mp4';
const THUMBNAIL_POSITION = 1.3;

generateVideoThumbnail(MY_VIDEO_URL, THUMBNAIL_POSITION, {
  size: {
    width: 640,
    height: 200,
  },
  format: 'image/jpeg',
  quality: 0.88,
}).then(thumbnailUrl => {
  const img = document.createElement('img');
  img.src = thumbnailUrl;
  document.body.appendChild(img);
});

API

generateVideoThumbnail

function generateVideoThumbnail(
  videoUrl: string,
  position: number,
  options?: GenerateVideoThumbnailOptions,
): Promise<string>;
  • videoUrl: The URL of the video.
  • position: The position in seconds where the thumbnail should be generated.
  • options: Optional options.

GenerateVideoThumbnailOptions

type GenerateVideoThumbnailOptions = Partial<{
  size: Partial<{
    width: number;
    height: number;
  }>;
  format: 'image/jpeg' | 'image/png' | 'image/webp';
  quality: number;
  onBlobCreated: (data: { blob: Blob; blobUrl: string; thumbnailPosition: number }): void;
}>;
  • size: The size of the thumbnail. Defaults to the original video size.
    • width and height are optional. If only one is specified, the other will be calculated to maintain the aspect ratio.
  • format: The format of the thumbnail. Default is 'image/jpeg'.
  • quality: The quality of the thumbnail. Default is 0.3. Applies only if the format is 'image/jpeg'.
  • onBlobCreated: A callback function that is called when the thumbnail blob is created.
    • blob: The thumbnail blob.
    • blobUrl: The URL of the thumbnail blob.
    • thumbnailPosition: The position of the thumbnail in seconds.

LICENSE

MIT

generate-video-dumbnail's People

Contributors

gumball12 avatar

Watchers

 avatar

generate-video-dumbnail's Issues

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.