web api instance method
VideoFrame: copyTo() method
Available in workers
The copyTo() method of the VideoFrame interface copies the contents of the VideoFrame to an ArrayBuffer.
Syntax
copyTo(destination)
copyTo(destination, options)
Parameters
destination- : An
ArrayBuffer, aTypedArray, or aDataViewto copy to.
- : An
optionsOptional- : An object containing the following:
rectOptional- : The rectangle of pixels to copy from the
VideoFrame. If unspecified, thevisibleRectwill be used. This is in the format of a dictionary object containing:x: The x-coordinate.y: The y-coordinate.width: The width of the frame.height: The height of the frame.
- : The rectangle of pixels to copy from the
layoutOptional- : 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
layoutis specified, the planes will be tightly packed.
- : An integer representing the number of bytes, including padding, used by each row of the plane.
Planes may not overlap. If no
- : A list containing the following values for each plane in the
formatOptional- : A pixel format for the pixel data in the
destination. Can be set to"RGBA","RGBX","BGRA","BGRX". If unspecified, theformatwill be used.
- : A pixel format for the pixel data in the
colorSpaceOptional- : Specifies the color space of the pixel data in the
destination. Can be set to"srgb"for the sRGB color space or"display-p3"for the display-p3 color space. Only applicable for RGB pixel formats. If unspecified,"srgbwill be used.
- : Specifies the color space of the pixel data in the
- : An object containing the following:
Return value
A Promise that resolves to the layout of the copy when the copy has completed.
Examples
The following example copies the entire contents of videoFrame.
let buffer = new Uint8Array(videoFrame.allocationSize());
let layout = await videoFrame.copyTo(buffer);
The following example converts a portion of the videoFrame to RGB format.
const videoRect = {
x: 100,
y: 100,
width: 80,
height: 60,
};
const options = {
rect: videoRect,
format: "RGBX",
colorSpace: "display-p3",
};
const size = videoFrame.allocationSize(options);
const buffer = new ArrayBuffer(size);
const layout = await videoFrame.copyTo(buffer, options);
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.