Skip to content

Commit 15bdd07

Browse files
committed
Add options to VideoSample allocationSize and copyTo methods, add explicit error message when format is null (closes #256)
1 parent 4dd747a commit 15bdd07

4 files changed

Lines changed: 530 additions & 20 deletions

File tree

docs/guide/packets-and-samples.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,11 @@ const bytesNeeded = videoSample.allocationSize(); // => number
378378
Then, use `copyTo` to copy the pixel data into the destination buffer:
379379
```ts
380380
const bytes = new Uint8Array(bytesNeeded);
381-
videoSample.copyTo(bytes);
381+
const planeLayout = await videoSample.copyTo(bytes);
382382
```
383383

384384
::: info
385-
The data will always be in the pixel format specified in the `format` field.
386-
387-
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()`.
385+
You can pass additional options to `allocationSize` and `copyTo` to extract data in a different pixel format.
388386
:::
389387

390388
---

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ export {
168168
AudioSampleCopyToOptions,
169169
VideoSample,
170170
VideoSampleInit,
171+
VideoSamplePixelFormat,
171172
VideoSampleColorSpace,
172173
CropRectangle,
174+
VIDEO_SAMPLE_PIXEL_FORMATS,
173175
} from './sample';
174176
export {
175177
AudioBufferSink,

0 commit comments

Comments
 (0)