Skip to main content

VideoDecoder

The VideoDecoder class decodes compressed video data (EncodedVideoChunk) into raw video frames (VideoFrame). It supports H.264, VP8, VP9, HEVC, and AV1 codecs with optional hardware acceleration.

Quick Example

Always call frame.close() in your output callback!VideoFrames hold native memory that is not visible to JavaScript’s garbage collector. Failing to close frames will cause memory leaks that can quickly exhaust system memory.

Constructor

Creates a new VideoDecoder instance.
init
VideoDecoderInit
required
Initialization object containing callbacks for decoded frames and errors.

Properties

state
CodecState
required
Current state of the decoder. Possible values:
decodeQueueSize
number
required
Number of decode operations currently pending in the queue. Useful for implementing backpressure to avoid memory exhaustion when decoding faster than frames can be processed.

Static Methods

isConfigSupported()

Checks if a decoder configuration is supported by the current system.
config
VideoDecoderConfig
required
The decoder configuration to test for support.
Returns: Promise<VideoDecoderSupport> - Object indicating whether the config is supported.

Methods

configure()

Configures the decoder with the specified codec and parameters.
config
VideoDecoderConfig
required
Configuration object specifying codec and video parameters.
Throws:
  • InvalidStateError if the decoder is closed
  • NotSupportedError if the codec is not supported

decode()

Queues an encoded video chunk for decoding.
chunk
EncodedVideoChunk
required
The encoded video chunk to decode. Can be a keyframe (type: 'key') or delta frame (type: 'delta').
Throws:
  • InvalidStateError if the decoder is not configured
  • DataError if the chunk data is malformed

flush()

Waits for all pending decode operations to complete.
Returns: Promise<void> - Resolves when all queued chunks have been decoded and all output callbacks have been invoked. Throws:
  • InvalidStateError if the decoder is not configured

reset()

Resets the decoder to the unconfigured state, discarding all pending work.
Aborts all pending decode operations and clears the decode queue. The decoder returns to the 'unconfigured' state and must be reconfigured before use. Throws:
  • InvalidStateError if the decoder is closed

close()

Closes the decoder and releases all resources.
After calling close(), the decoder cannot be used. Any pending decode operations are aborted.

addEventListener()

Adds an event listener for decoder events.
type
string
required
Event type. Currently only 'dequeue' is supported.
listener
() => void
required
Callback function to invoke when the event fires.
options
object
Event listener options.

removeEventListener()

Removes a previously added event listener.
type
string
required
Event type (e.g., 'dequeue').
listener
() => void
required
The callback function to remove.

Interfaces

VideoDecoderConfig

Configuration options for the video decoder.

VideoDecoderInit

Initialization callbacks for the decoder constructor.

VideoDecoderSupport

Result of isConfigSupported().

Hardware Decoding

Hardware-accelerated decoding uses GPU decoders for improved performance and reduced CPU usage. This is especially beneficial for 4K+ video or when processing multiple streams.
Hardware decoder availability depends on your system:
  • macOS: VideoToolbox (all Macs)
  • Windows/Linux: NVDEC (NVIDIA GPUs), VA-API (Intel/AMD)
  • Raspberry Pi: V4L2 M2M

See Also

VideoFrame

Raw video frame data output by the decoder

VideoEncoder

Encode VideoFrames into compressed video

EncodedVideoChunk

Compressed video data input to the decoder

Hardware Acceleration

Guide to GPU-accelerated encoding/decoding