From ea9b0501fda3a15003853b9b8fbaa59033a5a4b0 Mon Sep 17 00:00:00 2001 From: JonnyBurger Date: Thu, 6 Nov 2025 10:03:42 +0100 Subject: [PATCH] Preserve rotation when calling `.toVideoFrame()` --- src/sample.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/sample.ts b/src/sample.ts index 805aebe..b66b636 100644 --- a/src/sample.ts +++ b/src/sample.ts @@ -379,24 +379,34 @@ export class VideoSample implements Disposable { assert(this._data !== null); if (isVideoFrame(this._data)) { - return new VideoFrame(this._data, { + const init: VideoFrameInit = { timestamp: this.microsecondTimestamp, duration: this.microsecondDuration || undefined, // Drag 0 duration to undefined, glitches some codecs - }); + // @ts-expect-error - WebCodecs types do not yet support rotation + rotation: this.rotation, + }; + return new VideoFrame(this._data, init); } else if (this._data instanceof Uint8Array) { - return new VideoFrame(this._data, { + const init: VideoFrameBufferInit = { format: this.format!, codedWidth: this.codedWidth, codedHeight: this.codedHeight, timestamp: this.microsecondTimestamp, duration: this.microsecondDuration || undefined, colorSpace: this.colorSpace, - }); + // @ts-expect-error - WebCodecs types do not yet support rotation + rotation: this.rotation, + }; + + return new VideoFrame(this._data, init); } else { - return new VideoFrame(this._data, { + const init: VideoFrameInit = { timestamp: this.microsecondTimestamp, duration: this.microsecondDuration || undefined, - }); + // @ts-expect-error - WebCodecs types do not yet support rotation + rotation: this.rotation, + }; + return new VideoFrame(this._data, init); } }