Screenshot

Saves the current frame as a PNG, or hands it to you as a Blob.

import { screenshot } from "react-video-kit/screenshot";

Adds 946 B to a player1.6 KB on its ownSource

Adds a Save frame row to the settings menu. Pause on a frame you like below, open the settings menu, and save it.

0:00−0:000:00

Usage

tsx
import { VideoPlayer } from "react-video-kit/player";import { screenshot } from "react-video-kit/screenshot";const plugins = [screenshot()];<VideoPlayer src="/video.mp4" plugins={plugins} />;

Files are named for the frame's position, such as frame-00-01-30.png. Choose your own with filename, which gets the position in seconds:

tsx
screenshot({  filename: (time) => `first-light-${Math.floor(time)}.png`,});

Use the frame yourself

capture returns the frame as a Blob, for uploading or showing in your own interface.

tsx
"use client";import { useCommands } from "react-video-kit";import { screenshot } from "react-video-kit/screenshot";function AttachFrame({ onFrame }: { onFrame(frame: Blob): void }) {  const { capture } = useCommands(screenshot);  return (    <button      onClick={async () => {        const frame = await capture();        if (frame) onFrame(frame);      }}    >      Attach this frame    </button>  );}

Video from another origin

A browser only lets a page read a video's pixels when the video is on the same origin or is served with CORS. For a video on a CDN, allow your site in the Access-Control-Allow-Origin header and ask for it with CORS:

tsx
<VideoPlayer  src="https://cdn.example.com/video.mp4"  media={{ crossOrigin: "anonymous" }}  plugins={plugins}/>

Browsers don't hand out frames of protected video, so DRM content usually saves as a black picture.

Behaviour

  • capture never rejects. If the frame can't be read it returns null and sets error, where tainted means the browser refused to read the video.
  • download saves the file, tells the viewer how it went in a short message, and returns whether it worked.
  • The picture is saved at the video's own size, however large the player is on the page.
  • The message is announced to screen readers.

API

Options

OptionTypeDescription
filename?((time: number) => string)Names a saved file, given the position of the frame in seconds.

State

Read it with useVideoState(screenshot, (state) => …).

FieldTypeDescription
errorScreenshotError | nullWhy the last attempt failed, or null. tainted means the browser refused to read the video.
notice"saved" | "failed" | nullThe message on show, or null.
noticeVisiblebooleanTrue until that message starts to fade.

Commands

Call them with useCommands(screenshot).

CommandTypeDescription
capture() => Promise<Blob | null>The current frame as a PNG, or null with error set when it can't be read. Never rejects.
download() => Promise<boolean>Saves the current frame, shows the viewer the outcome, and returns whether it worked.

Parts

PartDescription
ScreenshotMenuThe row that saves the frame.
ScreenshotNoticeSays whether the frame was saved, also announced to screen readers.