VideoFrame Class

A frame of video or a decoded image (https://w3c.github.io/webcodecs/#videoframe): the frames created by an ImageDecoder. Its pixels are RGBA (8 bits per sample, not premultiplied, in the sRGB color space, or Display P3 for an image whose colors are outside of sRGB); its rotation and flip are the EXIF orientation of the image. A frame can be drawn on a canvas and used by createImageBitmap(); the frames cannot be constructed by the scripts (the decoders and the encoders of audio and video are not implemented).

public sealed class VideoFrame

Properties

NameDescription
CodedHeightGets the height of the pixels (before the rotation).
CodedRectGets the rectangle of the pixels at (0, 0), or null when the frame is closed.
CodedWidthGets the width of the pixels (before the rotation).
ColorSpaceGets the color space of the pixels.
DisplayHeightGets the height of the rendered frame (after the rotation).
DisplayWidthGets the width of the rendered frame (after the rotation).
DurationGets the presentation duration in microseconds, or null (e.g. a still image).
FlipGets whether the frame is flipped horizontally when it is rendered, after the rotation.
FormatGets the format of the pixels, or null when the frame is closed.
RotationGets the clockwise rotation in degrees applied when the frame is rendered, before the flip.
TimestampGets the presentation timestamp in microseconds.
VisibleRectGets the rectangle of the visible pixels (all the pixels of a decoded image), or null when the frame is closed.

CodedHeight

VideoFrame.cs

Gets the height of the pixels (before the rotation).

public uint CodedHeight { get; }

CodedRect

VideoFrame.cs

Gets the rectangle of the pixels at (0, 0), or null when the frame is closed.

public DomRectReadOnly? CodedRect { get; }

CodedWidth

VideoFrame.cs

Gets the width of the pixels (before the rotation).

public uint CodedWidth { get; }

ColorSpace

VideoFrame.cs

Gets the color space of the pixels.

public VideoColorSpace ColorSpace { get; }

DisplayHeight

VideoFrame.cs

Gets the height of the rendered frame (after the rotation).

public uint DisplayHeight { get; }

DisplayWidth

VideoFrame.cs

Gets the width of the rendered frame (after the rotation).

public uint DisplayWidth { get; }

Gets the presentation duration in microseconds, or null (e.g. a still image).

public ulong? Duration { get; }

Gets whether the frame is flipped horizontally when it is rendered, after the rotation.

public bool Flip { get; }

Gets the format of the pixels, or null when the frame is closed.

public VideoPixelFormat? Format { get; }

Gets the clockwise rotation in degrees applied when the frame is rendered, before the flip.

public double Rotation { get; }

Timestamp

VideoFrame.cs

Gets the presentation timestamp in microseconds.

public long Timestamp { get; }

VisibleRect

VideoFrame.cs

Gets the rectangle of the visible pixels (all the pixels of a decoded image), or null when the frame is closed.

public DomRectReadOnly? VisibleRect { get; }

Methods

NameDescription
AllocationSize(VideoFrameCopyToOptions?)Returns the number of bytes VideoFrame.CopyTo writes with the options (https://w3c.github.io/webcodecs/#dom-videoframe-allocationsize).
Clone()Creates a frame that references the same pixels (https://w3c.github.io/webcodecs/#dom-videoframe-clone).
Close()Releases the reference to the pixels (https://w3c.github.io/webcodecs/#close-videoframe): the frame cannot be used anymore.
CopyTo(Memory<byte>, VideoFrameCopyToOptions?)Copies the pixels of the frame into a buffer (https://w3c.github.io/webcodecs/#dom-videoframe-copyto), converted to the format and the color space of the options when they are given.
Metadata()Returns a copy of the metadata of the frame (https://w3c.github.io/webcodecs/#dom-videoframe-metadata).

AllocationSize(VideoFrameCopyToOptions?)

VideoFrame.cs

Returns the number of bytes VideoFrame.CopyTo writes with the options (https://w3c.github.io/webcodecs/#dom-videoframe-allocationsize).

public uint AllocationSize(VideoFrameCopyToOptions? options = null)

Parameters

options VideoFrameCopyToOptions?

Returns

uint

Exceptions

DomException
An InvalidStateError when the frame is closed, a NotSupportedError for a format other than RGBA, RGBX, BGRA and BGRX.
TypeErrorException
The rectangle or the layout is invalid.

See also

Creates a frame that references the same pixels (https://w3c.github.io/webcodecs/#dom-videoframe-clone).

public VideoFrame Clone()

Returns

VideoFrame

Exceptions

DomException
An InvalidStateError when the frame is closed.

See also

Releases the reference to the pixels (https://w3c.github.io/webcodecs/#close-videoframe): the frame cannot be used anymore.

public void Close()

CopyTo(Memory<byte>, VideoFrameCopyToOptions?)

VideoFrame.cs

Copies the pixels of the frame into a buffer (https://w3c.github.io/webcodecs/#dom-videoframe-copyto), converted to the format and the color space of the options when they are given.

public Task<IReadOnlyList<PlaneLayout>> CopyTo(Memory<byte> destination, VideoFrameCopyToOptions? options = null)

Parameters

destination Memory<byte>
options VideoFrameCopyToOptions?

Returns

Task<IReadOnlyList<PlaneLayout>> A task that completes with the layout of the planes in the buffer (in a task of the event loop).

See also

Metadata()

VideoFrame.cs

Returns a copy of the metadata of the frame (https://w3c.github.io/webcodecs/#dom-videoframe-metadata).

public VideoFrameMetadata Metadata()

Returns

VideoFrameMetadata

Exceptions

DomException
An InvalidStateError when the frame is closed.

See also