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.
"use client";import { VideoPlayer } from "react-video-kit/player";import { screenshot } from "react-video-kit/screenshot";const plugins = [screenshot()];export default function Screenshot() { return <VideoPlayer src="/media/sample-720.mp4" poster="/media/poster.jpg" plugins={plugins} load="visible" />;}Usage
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:
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.
"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:
<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
capturenever rejects. If the frame can't be read it returns null and setserror, wheretaintedmeans the browser refused to read the video.downloadsaves 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
| Option | Type | Description |
|---|---|---|
| filename? | ((time: number) => string) | Names a saved file, given the position of the frame in seconds. |
State
Read it with useVideoState(screenshot, (state) => …).
| Field | Type | Description |
|---|---|---|
| error | ScreenshotError | null | Why the last attempt failed, or null. tainted means the browser refused to read the video. |
| notice | "saved" | "failed" | null | The message on show, or null. |
| noticeVisible | boolean | True until that message starts to fade. |
Commands
Call them with useCommands(screenshot).
| Command | Type | Description |
|---|---|---|
| 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
| Part | Description |
|---|---|
| ScreenshotMenu | The row that saves the frame. |
| ScreenshotNotice | Says whether the frame was saved, also announced to screen readers. |