Add options to VideoSample allocationSize and copyTo methods, add explicit error message when format is null (closes #256)

This commit is contained in:
Vanilagy
2025-12-17 15:10:25 +01:00
parent 4dd747a0a6
commit 15bdd072e1
4 changed files with 530 additions and 20 deletions
+2 -4
View File
@@ -378,13 +378,11 @@ const bytesNeeded = videoSample.allocationSize(); // => number
Then, use `copyTo` to copy the pixel data into the destination buffer:
```ts
const bytes = new Uint8Array(bytesNeeded);
videoSample.copyTo(bytes);
const planeLayout = await videoSample.copyTo(bytes);
```
::: info
The data will always be in the pixel format specified in the `format` field.
To convert the data into a different pixel format, or to extract only a section of the frame, please use the [`allocationSize`](https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame/allocationSize) and [`copyTo`](https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame/copyTo) methods on `VideoFrame` instead. Get a `VideoFrame` by running `videoSample.toVideoFrame()`.
You can pass additional options to `allocationSize` and `copyTo` to extract data in a different pixel format.
:::
---