UNPKG

@face-auth/face-id-video

Version:

Utility library for capturing photos from webcam video streams in the browser. Handles camera selection, image formatting, and output for face authentication APIs.

80 lines (54 loc) 2.1 kB
# @face-auth/face-id-video <h1 align="center"> <img src="https://www.face-auth.me/wp-content/uploads/2024/08/face-auth-logo-allblue.webp" width=300 alt="Face Auth"/> </h1> <div align="center"> <img src="https://img.shields.io/badge/Version%20-%200.0.2-blue.svg" alt="Version"/> <img src="https://img.shields.io/badge/%F0%9F%93%85%20Last%20update%20-%20August%201%2C%202025-brightgreen.svg" alt="Last update"/> <img src="https://img.shields.io/badge/%E2%9C%94%20Target%20Environment%20-%20Browser%20only-brightgreen.svg" alt="Browser only"/> </div> <br/> ## Introduction `@face-auth/face-id-video` is a utility package designed to simplify webcam interaction and image capture in the browser. It handles everything related to video stream management, camera device selection, photo capture, and formatting the output in a format ready to be sent to the [`@face-auth/face-id`](https://www.npmjs.com/package/@face-auth/face-id) API. It is designed to work independently, but it is especially useful when combined with `@face-auth/face-id` to provide seamless face authentication or registration experiences. --- ## Features - Get available video input devices. - Select and use the preferred or user-specified camera. - Start and stop video streams. - Capture the current frame from the video. - Output the image in a `Blob` or `Base64` format, ready for upload. - Fully browser-compatible and mobile-ready. --- ## Installation ```bash npm install @face-auth/face-id-video ``` ## Usage ### 1. Basic setup ```ts import { FaceVideo } from "@face-auth/face-id-video"; const videoElement = document.getElementById("videoRef") as HTMLVideoElement; const faceVideo = new FaceVideo(videoElement); ``` ### 2. Start the camera ```ts await faceVideo.start({ width: 640, height: 480, mirrored: true }); ``` ### 3. Capture a photo ```ts const result = await faceVideo.capture({ format: "base64", mimeType: "image/jpeg", quality: 0.9 }); ``` ### 4. Stop the camera ```ts faceVideo.stop(); ```