npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

video-frame-screenshot

v1.1.0

Published

capture video frames by canvas

Downloads

166

Readme

Video Frame Capture Tool

A tool for capturing screenshots from specific frames of a video

Installation

  npm install video-frame-screenshot

Usage/Examples

import { useState } from 'react';
import { captureFrame } from 'video-frame-screenshot'

const App = () => {
  const [frames, setFrames] = useState<string[]>([]);

  const handleInputOnChange = async (
    e: React.ChangeEvent<HTMLInputElement>
  ) => {
    const file = e.target.files?.[0];
    if (!file) return;
    const newFrames: string[] = [];

    for (let i = 0; i < 10; i++) {
      const frame = await captureFrame(file, i * 1);
      if (frame) {
        newFrames.push(frame.url);
      }
    }

    setFrames(newFrames);
  };

  return (
    <div>
      <input type='file' onChange={handleInputOnChange} />
      <div>
        {frames.map((url, index) => (
          <img key={index} src={url} alt={`frame-${index}`} />
        ))}
      </div>
    </div>
  );
};

API Reference

TS Types

  type FrameCaptureResult = { blob: Blob; url: string } | null;

captureFrame(file: File, time: number = 0): Promise<FrameCaptureResult>

Captures a frame from a video file at a specified time.

| Parameter | Type | Description | | :-------- | :------- | :----------------------------------------------------------- | | file | File | Required Video file (e.g., .mp4) to capture frame from | | time | number | Time in seconds to capture the frame. Defaults to 0 (start of video) |

captureFrameAtTimeRange(file: File, startTime: number, endTime: number): Promise<FrameCaptureResult | null>

Captures a frame from a video within a specified time range. Returns null if the current video time exceeds endTime.

| Parameter | Type | Description | | :---------- | :------- | :----------------------------------------------------------- | | file | File | Required Video file (e.g., .mp4) to capture frame from | | startTime | number | Required Start time in seconds to begin frame capture | | endTime | number | Required End time in seconds where capture stops |

downloadFrame(frame: FrameCaptureResult, filename: string = 'frame.png'): void

Downloads the captured frame as an image file.

| Parameter | Type | Description | | :--------- | :------------------- | :----------------------------------------------------------- | | frame | FrameCaptureResult | Required The captured frame result to download | | filename | string | Filename for the downloaded file (defaults to frame.png) |