Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Note: This feature is available in Dedicated Web Workers.
The copyTo() method of the VideoFrame interface copies the contents of the VideoFrame to an ArrayBuffer.
copyTo(destination) copyTo(destination, options)
destinationAn ArrayBuffer, a TypedArray, or a DataView to copy to.
options OptionalAn object containing the following:
rect OptionalThe rectangle of pixels to copy from the VideoFrame. If unspecified, the visibleRect will 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.layout OptionalA list containing the following values for each plane in the VideoFrame:
format OptionalA pixel format for the pixel data in the destination. Can be set to "RGBA", "RGBX", "BGRA", "BGRX". If unspecified, the format will be used.
colorSpace OptionalSpecifies 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, "srgb will be used.
A Promise that resolves to the layout of the copy when the copy has completed.
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);
| Specification |
|---|
| WebCodecs> # dom-videoframe-copyto> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
copyTo |
94 | 94 | 130 | 80 | 16.4 | 94 | 130 | 66 | 16.4 | 17.0 | 94 | 16.4 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame/copyTo