Skip to main content

Your First Video Decode

This tutorial will have you decoding video frames in under 5 minutes. We’ll decode the H.264 video you created in the Quick Start tutorial.
1

Prerequisites

Make sure you’ve completed the Quick Start tutorial and have:
  • node-webcodecs installed
  • An encoded video file (output.h264)
  • Basic understanding of VideoEncoder
If you don’t have an encoded video, run the Quick Start example first.
2

Create a decoder

Create a file called decode.js:
3

Configure the decoder

Add configuration code:
The decoder configuration must match the encoder’s output codec and dimensions.
4

Decode the video

Read and decode the H.264 file:
5

Run it!

Expected Output:

Complete Encode/Decode Roundtrip

Here’s a complete example that encodes AND decodes in the same script:

What Just Happened?

The output callback receives:
  • frame: VideoFrame containing decoded pixel data
  • The frame is in a native format (usually I420 or NV12)
  • codec: Must match the encoded video’s codec
  • codedWidth/Height: Must match the encoded dimensions
  • description: Codec-specific configuration (SPS/PPS for H.264)
  • type: 'key' for keyframes (I-frames), 'delta' for P/B-frames
  • timestamp: Presentation timestamp in microseconds
  • data: Raw encoded bitstream data
The encoder provides decoder configuration on the first keyframe. This contains:
  • codec: Codec string
  • codedWidth/codedHeight: Dimensions
  • description: Codec extradata (SPS/PPS for H.264, etc.)

Working with Decoded Frames

Always close decoded frames!
VideoFrame objects hold native memory that JavaScript’s GC cannot see. Always call .close() when done.

Accessing Pixel Data

Common Mistakes

Wrong codec string
Missing description (extradata)
For H.264/HEVC, the description field contains critical codec parameters (SPS/PPS). Without it, decoding will fail.
Not awaiting flush()

Next Steps

API Reference

Complete VideoDecoder documentation

Transcode Video

Learn to transcode between codecs

Real-World Demo

Process actual video files

Troubleshooting

Common decoding issues