VideoSample
Represents a raw, unencoded video frame. Provides methods for creating, manipulating, and converting video frames across different formats.Constructor
VideoSampleInit
required
Initialization options for the video sample.
Creating VideoSamples
From VideoFrame
VideoSample from a VideoFrame.
From Canvas
VideoSample by rendering a canvas element.
From Raw Pixels
VideoSample from raw pixel data.
Properties
VideoSamplePixelFormat
The internal pixel format in which the frame is stored. One of 21 supported formats including I420, NV12, RGBA, etc.
number
The width of the frame in pixels.
number
The height of the frame in pixels.
number
The display width accounting for rotation and pixel aspect ratio.
number
The display height accounting for rotation and pixel aspect ratio.
Rotation
The rotation of the frame in degrees (0, 90, 180, 270), clockwise.
number
The presentation timestamp in seconds.
number
The duration in seconds.
VideoSampleColorSpace
The color space information for the frame.
Methods
toVideoFrame()
Converts this sample to aVideoFrame.
copyToCanvas()
Draws this video sample onto a canvas.copyPixelsTo()
Copies the raw pixel data of this sample to a destination buffer.clone()
Creates a copy of this video sample.close()
Releases underlying resources. You must call this when you’re done using the sample.AudioSample
Represents a raw, unencoded audio buffer. Provides methods for creating, manipulating, and converting audio data.Constructor
AudioSampleInit
required
Initialization options for the audio sample.
Creating AudioSamples
From AudioData
AudioSample from an AudioData.
From AudioBuffer
AudioSample from an AudioBuffer.
From Raw Audio Data
AudioSample from raw audio data.
Properties
AudioSampleFormat
The internal format of the audio data (e.g., ‘s16’, ‘f32’, ‘s32’, ‘f32-planar’).
number
The number of audio channels (e.g., 2 for stereo).
number
The number of audio frames in this sample.
number
The sample rate in Hz (e.g., 48000).
number
The presentation timestamp in seconds.
number
The duration in seconds.
Methods
toAudioData()
Converts this sample to anAudioData.
toAudioBuffer()
Converts this sample to anAudioBuffer.
copyDataTo()
Copies the raw audio data to a destination buffer.clone()
Creates a copy of this audio sample.close()
Releases underlying resources. You must call this when you’re done using the sample.VideoSamplePixelFormat
The internal pixel format with which a VideoSample is stored. See WebCodecs pixel formats for more details.VideoSampleColorSpace
Color space information for video samples.Example
See also
- Packets - Encoded compressed media data
- Packets and samples concept - Understanding the difference
- VideoSampleSource - Add video samples to output
- AudioSampleSource - Add audio samples to output
- VideoSampleSink - Extract video samples from input
- AudioSampleSink - Extract audio samples from input