Skip to content

Video for Linux 2 (V4L2 API)

Node.js Browser (Client) Experimental

An input type that allows Smelter to capture video using the Video for Linux 2 API. V4L2 devices can be found in paths that look like this:

  • /dev/video[N], where N is the device number,
  • /dev/v4l/by-id/[DEVICE ID],
  • /dev/v4l/by-path/[PCI/USB PATH].

Usage

Example request

v4l2InputExample.tsx
import Smelter from "@swmansion/smelter-node";
async function run() {
const smelter = new Smelter();
await smelter.init();
await smelter.registerInput("example", {
type: "v4l2",
path: "/dev/video0",
format: "yuyv",
resolution: {
width: 1920,
height: 1080,
},
framerate: 30,
});
}
void run();

Reference

Type definition

type RegisterV4l2Input = {
type: "v4l2";
path: string;
format: "yuyv" | "nv12";
resolution: {
width: number;
height: number;
};
framerate: number | string;
required?: boolean;
};

Parameters for registering a V4L2 device as an input.

Properties

path

Path to the V4L2 device.

  • Type: string

format

A format used for video capture.

  • Type: "yuyv" | "nv12"
  • Supported values:
    • yuyv - YUYV, which is a form of interleaved 4:2:2 YUV.
    • nv12 - NV12, which is a form of planar 4:2:0 YUV, with one plane for Y and a second plane for interleaved UV.

resolution

The capture resolution. This value may be changed by the device driver to the closest resolution supported at the selected format.

  • Type: { width: number; height: number; }

framerate

Video framerate. This value may be changed by the device driver to the closest framerate supported at the selected format and resolution. Has to be either a u32 or a string in the "NUM/DEN" form, representing a fraction.

  • Type: number | string

required

Determines if the input stream is essential for output frame production. If set to true and the stream is delayed, Smelter will postpone output frames until the stream is received.

  • Type: bool
  • Default value: false