files/en-us/web/api/videoframe/copyto/index.md
{{APIRef("Web Codecs API")}}{{AvailableInWorkers("window_and_dedicated")}}
The copyTo() method of the {{domxref("VideoFrame")}} interface copies the contents of the VideoFrame to an ArrayBuffer.
copyTo(destination)
copyTo(destination, options)
destination
ArrayBuffer, a {{jsxref("TypedArray")}}, or a {{jsxref("DataView")}} to copy to.options {{Optional_Inline}}
rect {{Optional_Inline}}
VideoFrame. If unspecified, the {{domxref("VideoFrame.visibleRect","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 {{Optional_Inline}}
VideoFrame:
offset
stride
layout is specified, the planes will be tightly packed.format {{Optional_Inline}}
destination. Can be set to "RGBA", "RGBX", "BGRA", "BGRX". If unspecified, the {{domxref("VideoFrame.format","format")}} will be used.colorSpace {{Optional_Inline}}
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);
{{Specifications}}
{{Compat}}