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.0.0

Published

capture video frames by canvas

Downloads

115

Readme

视频帧捕获工具

获取视频某一帧的截图

安装

  npm install video-frame-screenshot

使用方法/示例

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 参考

TS 类型

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

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

从指定的视频文件中捕获指定时间的帧。

| 参数 | 类型 | 描述 | | :----- | :------- | :----------------------------------------------------------- | | file | File | 必选 视频文件(例如 .mp4.webm 等),用于从中捕获帧 | | time | number | 指定捕获帧的时间(秒)。默认为 0(视频开始时) |

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

在指定的时间范围内捕获视频的某一帧。如果视频的当前时间超出了 endTime,则返回 null

| 参数 | 类型 | 描述 | | :---------- | :------- | :----------------------------------------------------------- | | file | File | 必选 视频文件(例如 .mp4.webm 等),用于从中捕获帧 | | startTime | number | 必选 开始时间(秒),从该时间开始捕获帧 | | endTime | number | 必选 结束时间(秒),在该时间点捕获停止 |

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

将捕获的帧下载为图像文件。

| 参数 | 类型 | 描述 | | :--------- | :------------------- | :----------------------------------------------------------- | | frame | FrameCaptureResult | 必选 视频文件(例如 .mp4.webm 等),用于从中捕获帧 | | filename | string | 下载的文件名(默认为 frame.png) |