ImageDecoder
TheImageDecoder class decodes compressed image data (JPEG, PNG, WebP, GIF, AVIF) into VideoFrame objects that can be processed, edited, or re-encoded.
This implementation follows the W3C WebCodecs ImageDecoder specification.
Quick Example
Decode a JPEG or PNG image into a VideoFrame:Supported Formats
Use
ImageDecoder.isTypeSupported() to check format support at runtime.
Constructor
Parameters
ImageDecoderInit
required
Configuration object for the decoder.
Example
Accessors
boolean
Whether all image data has been received and parsed.For images loaded from a
Buffer, this is true immediately after construction.
For images loaded from a ReadableStream, this becomes true when the stream ends.Promise<void>
A promise that resolves when
complete becomes true.Use this to wait for the image to be fully loaded before decoding:string
The MIME type of the image being decoded.
Static Methods
isTypeSupported()
Example: Check format support
Example: Check format support
type(string): The MIME type to check
Promise<boolean> - Resolves to true if the format is supported
Instance Methods
decode()
Example: Basic decode
Example: Basic decode
Example: Animated GIF frame extraction
Example: Animated GIF frame extraction
Example: WebP animation processing
Example: WebP animation processing
ImageDecodeOptions
Optional decode options.
Promise<ImageDecodeResult> - Resolves to an object containing the decoded frame
reset()
Example: Reset and re-decode
Example: Reset and re-decode
void
close()
Example: Proper cleanup
Example: Proper cleanup
void
Interfaces
ImageDecodeResult
The result of a decode operation.VideoFrame
required
The decoded image as a
VideoFrame. You must call close() on this frame when done to release memory.boolean
required
Whether the image is fully decoded. For animated images, this indicates whether this is the last frame.
ImageDecodeOptions
Options for thedecode() method.
number
The index of the frame to decode (0-based). Defaults to
0.boolean
Whether to only return complete frames. Defaults to
true.ImageDecoderInit
Configuration for creating anImageDecoder.
BufferSource | ReadableStream<BufferSource>
required
The compressed image data.
string
required
The MIME type of the image.
'default' | 'none'
Color space conversion mode.
number
Desired output width for scaling.
number
Desired output height for scaling.
boolean
Whether to prefer animated representation.
See Also
VideoFrame
Learn about the VideoFrame class returned by decode()
VideoEncoder
Encode decoded images into video
Thumbnail Generation
Generate thumbnails from images and videos
Video Transcoding
Complete transcoding workflow