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.Prerequisites
Make sure you’ve completed the Quick Start tutorial and have:
node-webcodecsinstalled- An encoded video file (
output.h264) - Basic understanding of VideoEncoder
Configure the decoder
Add configuration code:
The decoder configuration must match the encoder’s output codec and dimensions.
Complete Encode/Decode Roundtrip
Here’s a complete example that encodes AND decodes in the same script:What Just Happened?
VideoDecoder setup
VideoDecoder setup
output callback receives:- frame:
VideoFramecontaining decoded pixel data - The frame is in a native format (usually
I420orNV12)
Configuration
Configuration
- codec: Must match the encoded video’s codec
- codedWidth/Height: Must match the encoded dimensions
- description: Codec-specific configuration (SPS/PPS for H.264)
EncodedVideoChunk
EncodedVideoChunk
- type:
'key'for keyframes (I-frames),'delta'for P/B-frames - timestamp: Presentation timestamp in microseconds
- data: Raw encoded bitstream data
Decoder config from encoder
Decoder config from encoder
codec: Codec stringcodedWidth/codedHeight: Dimensionsdescription: Codec extradata (SPS/PPS for H.264, etc.)