Skip to main content
Version: next

Video Decoder

All built-in video decoders implement the ScrcpyVideoDecoder interface from @yume-chan/scrcpy-decoder-shared. This page describes the common interface shared by all decoders.

Interface

import type { ScrcpyVideoDecoder } from "@yume-chan/scrcpy-decoder-shared";

The ScrcpyVideoDecoder interface provides a unified API for decoding and rendering Scrcpy video streams. Both the H264BSD decoder and WebCodecs decoder implement this interface.

Properties

PropertyTypeDescription
type"software" | "hardware"Whether the decoder uses software or hardware decoding
rendererType"software" | "hardware"Whether the renderer uses software or hardware rendering
writableWritableStream<ScrcpyVideoStreamPacket>Writable stream that accepts video packets for decoding
pausedbooleanWhether the decoder is currently paused
widthnumberCurrent video width in pixels
heightnumberCurrent video height in pixels
sizeChangedEvent<{ width, height }>Event fired when the video size changes
framesDecodednumberNumber of frames successfully decoded
framesSkippedDecodingnumberNumber of frames skipped by the decoder
framesRenderednumberNumber of frames drawn on the renderer
framesDisplayednumberNumber of frames visible to the user
framesSkippedRenderingnumberNumber of frames not drawn because the renderer can't keep up
decoderResetCountnumberNumber of times the decoder was reset to catch up with new keyframes

Methods

MethodDescription
pause()Pause the decoder
resume()Resume the decoder if it was paused
trackDocumentVisibility(document)Automatically pause/resume based on document visibility
dispose()Clean up decoder resources

Common usage

Regardless of which decoder you use, the basic usage pattern is the same:

  1. Create a decoder instance
  2. Pipe the video stream into decoder.writable
  3. Handle size changes via decoder.sizeChanged
  4. Optionally pause the decoder when the canvas is not visible
  5. Monitor rendering metrics for performance insights

Create a decoder

Each decoder has its own constructor with different options. See the specific decoder documentation for details:

After creating the decoder, append the render target to the DOM:

// For H264BSD decoder:
document.body.appendChild(decoder.canvas as HTMLCanvasElement);

// For WebCodecs decoder:
document.body.appendChild(decoder.renderer.canvas);