Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

capture-video-frame

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capture-video-frame

A micro-library for taking screenshots from a running HTML5 video.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
1K
60.64%
Maintainers
1
Weekly downloads
 
Created
Source

capture-video-frame

A micro-library for taking screenshots from a running HTML5 video. Built to work together with getUserMedia.js

Installation

$ npm install --save capture-video-frame

Example

HTML:

<video id="my-video" autoplay>
  <source src="movie.mp4" type="video/mp4" />
</video>

<img id="my-screenshot" />

JavaScript:

import captureVideoFrame from "capture-video-frame.js";

// When you want to record the image
const frame = captureVideoFrame("my-video-id", "png");

// Show the image
const img = document.getElementById("my-screenshot");
img.setAttribute("src", frame.dataUri);

// Upload the image...
const formData = new FormData();
formData.append("file", frame.blob, `my-screenshot.${frame.format}`);

// ...with plain JS
const request = new XMLHttpRequest();
request.open("POST", "/api/upload", true);
request.setRequestHeader(
  "Content-Type",
  "application/multipart/form-data; charset=UTF-8"
);
request.send(formData);

// ...or with jQuery
$.ajax({
  url: "/api/upload",
  method: "POST",
  data: formData,
  processData: false,
  contentType: false,
});

Browser support

Tested on current Chrome and Firefox.

API

captureVideoFrame(source, format, quality)

Parameters

source (element or string, mandatory) Source video. If string, id of the element.

format (string, optional) Output image format. Can be either png or jpeg. png is the default.

quality (number, optional) A Number between 0 and 1 indicating image quality if the requested type is image/jpeg or image/webp. The default value is 0.92.

Return value

  • Object with blob, dataUri, and format properties if the capture succeeded
  • false if the capture failed.

Image blob can be easily uploaded to the server using XHR2 FormData API.

Image data URI can be easily set as <img> src attribute to show the captured image.

License

MIT

Keywords

js

FAQs

Package last updated on 19 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts