VideoFrame: VideoFrame() constructor

Baseline 2024 *
Newly available

Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

* Some parts of this feature may have varying levels of support.

Note: This feature is available in Dedicated Web Workers.

The VideoFrame() constructor creates a new VideoFrame object representing a frame of a video.

Syntax

js
new VideoFrame(image)
new VideoFrame(image, options)
new VideoFrame(data, options)

Parameters

The first type of constructor (see above) creates a new VideoFrame from an image. Its parameters are:

image

An image containing the image data for the new VideoFrame. It can be one of the following objects: an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, an OffscreenCanvas, or another VideoFrame.

options Optional

An object containing the following:

duration Optional

An integer representing the duration of the frame in microseconds.

timestamp

An integer representing the timestamp of the frame in microseconds.

alpha Optional

A string, describing how the user agent should behave when dealing with alpha channels. The default value is "keep".

  • "keep": Indicates that the user agent should preserve alpha channel data.
  • "discard": Indicates that the user agent should ignore or remove alpha channel data.
visibleRect Optional

An object representing the visible rectangle of the VideoFrame, containing the following:

x

The x-coordinate.

y

The y-coordinate.

width

The width of the frame.

height

The height of the frame.

displayWidth Optional

The width of the VideoFrame when displayed after applying aspect-ratio adjustments.

displayHeight Optional

The height of the VideoFrame when displayed after applying aspect-ratio adjustments.

flip Optional

A boolean. If true, horizontal mirroring is applied. Defaults to false.

rotation Optional

An integer representing the rotation (0, 90, 180, or 270) in degrees clockwise. Defaults to 0. Arbitrary numbers (including negatives) are rounded to the next quarter turn.

The second type of constructor (see above) creates a new VideoFrame from an ArrayBuffer. Its parameters are:

data

An ArrayBuffer, a TypedArray, or a DataView containing the data for the new VideoFrame.

options

An object containing the following:

format

A string representing the video pixel format. One of the following strings, which are fully described on the page for the format property:

  • "I420"
  • "I420A"
  • "I422"
  • "I444"
  • "NV12"
  • "RGBA"
  • "RGBX"
  • "BGRA"
  • "BGRX"
codedWidth

Width of the VideoFrame in pixels, potentially including non-visible padding, and prior to considering potential ratio adjustments.

codedHeight

Height of the VideoFrame in pixels, potentially including non-visible padding, and prior to considering potential ratio adjustments.

timestamp

An integer representing the timestamp of the frame in microseconds.

duration Optional

An integer representing the duration of the frame in microseconds.

layout Optional

A list containing the following values for each plane in the VideoFrame:

offset

An integer representing the offset in bytes where the given plane begins.

stride

An integer representing the number of bytes, including padding, used by each row of the plane. Planes may not overlap. If no layout is specified, the planes will be tightly packed.

visibleRect Optional

An object representing the visible rectangle of the VideoFrame, containing the following:

x

The x-coordinate.

y

The y-coordinate.

width

The width of the frame.

height

The height of the frame.

displayWidth Optional

The width of the VideoFrame when displayed after applying aspect ratio adjustments.

displayHeight Optional

The height of the VideoFrame when displayed after applying aspect ratio adjustments.

colorSpace

An object representing the color space of the VideoFrame, containing the following:

primaries

A string representing the video color primaries, described on the page for the VideoColorSpace.primaries property.

transfer

A string representing the video color transfer function, described on the page for the VideoColorSpace.transfer property.

matrix

A string representing the video color matrix, described on the page for the VideoColorSpace.matrix property.

fullRange

A Boolean. If true, indicates that full-range color values are used.

transfer

An array of ArrayBuffers that VideoFrame will detach and take ownership of. If the array contains the ArrayBuffer backing data, VideoFrame will use that buffer directly instead of copying from it.

flip Optional

A boolean. If true, horizontal mirroring is applied. Defaults to false.

rotation Optional

An integer representing the rotation (0, 90, 180, or 270) in degrees clockwise. Defaults to 0. Arbitrary numbers (including negatives) are rounded to the next quarter turn.

Examples

The following examples are from the article Video processing with WebCodecs. In this first example, a VideoFrame is created from a canvas.

js
const cnv = document.createElement("canvas");
// draw something on the canvas
// …
const frameFromCanvas = new VideoFrame(cnv, { timestamp: 0 });

In the following example a VideoFrame is created from a TypedArray.

js
const pixelSize = 4;
const init = {
  timestamp: 0,
  codedWidth: 320,
  codedHeight: 200,
  format: "RGBA",
};
const data = new Uint8Array(init.codedWidth * init.codedHeight * pixelSize);
for (let x = 0; x < init.codedWidth; x++) {
  for (let y = 0; y < init.codedHeight; y++) {
    const offset = (y * init.codedWidth + x) * pixelSize;
    data[offset] = 0x7f; // Red
    data[offset + 1] = 0xff; // Green
    data[offset + 2] = 0xd4; // Blue
    data[offset + 3] = 0x0ff; // Alpha
  }
}
init.transfer = [data.buffer];
const frame = new VideoFrame(data, init);

Specifications

Specification
WebCodecs
# dom-videoframe-videoframe

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
VideoFrame() constructor
Chrome – Full support
Chrome 94 (Release date: 2021-09-21)
footnote Full support
Edge – Full support
Edge 94 (Release date: 2021-09-24)
footnote Full support
Firefox – Full support
Firefox 130 (Release date: 2024-09-03)
footnote Full support
Opera – Full support
Opera 80 (Release date: 2021-10-05)
footnote Full support
Safari – Full support
Safari 16.4 (Release date: 2023-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 94 (Release date: 2021-09-21)
footnote Full support
Firefox for Android – Full support
Firefox for Android 130 (Release date: 2024-09-03)
footnote Full support
Opera Android – Full support
Opera Android 66 (Release date: 2021-12-15)
footnote Full support
Safari on iOS – Full support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 17 (Release date: 2022-05-04)
footnote Full support
WebView Android – Full support
WebView Android 94 (Release date: 2021-09-21)
footnote Full support
WebView on iOS – Full support
WebView on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
flip option
Experimental
Chrome – Full support
Chrome 138 (Release date: 2025-06-24)
footnote Full support
Edge – Full support
Edge 138 (Release date: 2025-06-26)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 122 (Release date: 2025-09-11)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 138 (Release date: 2025-06-24)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 91 (Release date: 2025-08-19)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 138 (Release date: 2025-06-24)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
metadata option
Experimental
Chrome – Full support
Chrome 145 (Release date: 2026-02-10)
footnote Full support
Edge – Full support
Edge 145 (Release date: 2026-02-14)
footnote Full support
Firefox – No support
Firefox
footnote
footnote See bug 1802053
Opera – Full support
Opera 129 (Release date: 2026-03-18)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 145 (Release date: 2026-02-10)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1802053
Opera Android – Full support
Opera Android 96 (Release date: 2026-03-10)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 145 (Release date: 2026-02-10)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
rotation option
Experimental
Chrome – Full support
Chrome 138 (Release date: 2025-06-24)
footnote Full support
Edge – Full support
Edge 138 (Release date: 2025-06-26)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 122 (Release date: 2025-09-11)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 138 (Release date: 2025-06-24)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 91 (Release date: 2025-08-19)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 138 (Release date: 2025-06-24)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.