ya-webadb/libraries/scrcpy-decoder-tinyh264
2022-07-19 16:45:26 +08:00
..
src fix(scrcpy): remove deprecated export 2022-07-19 16:45:26 +08:00
jest.config.js refactor(scrcpy): move decoders to own packages 2022-07-19 16:36:34 +08:00
LICENSE refactor(scrcpy): move decoders to own packages 2022-07-19 16:36:34 +08:00
package.json refactor(scrcpy): move decoders to own packages 2022-07-19 16:36:34 +08:00
README.md refactor(scrcpy): move decoders to own packages 2022-07-19 16:36:34 +08:00
tsconfig.build.json refactor(scrcpy): move decoders to own packages 2022-07-19 16:36:34 +08:00
tsconfig.json refactor(scrcpy): move decoders to own packages 2022-07-19 16:36:34 +08:00
tsconfig.test.json refactor(scrcpy): move decoders to own packages 2022-07-19 16:36:34 +08:00

@yume-chan/scrcpy

Decode and render video stream using TinyH264, the old Android H.264 software decoder (now deprecated and removed), compiled into WebAssembly, and wrapped in Web Worker to prevent blocking the main thread.

The video stream will be decoded into YUV frames, and converted to RGB using a WebGL shader, all on CPU. So it's slow and inefficient, but it works on most browsers.

WARNING: The public API is UNSTABLE. If you have any questions, please open an issue.

Compatibility

Chrome Firefox Safari Performance Supported H.264 profile/level
57 52 11 Poor Baseline level 4

Usage

The bundler you use must also support the new Worker(new URL('./worker.js', import.meta.url)) syntax. It's known to work with Webpack 5.

It only supports Baseline level 4 codec, but many newer devices default to higher profile/levels. You can limit it by the codecOptions option.

new ScrcpyOptions1_24({
    codecOptions: new CodecOptions({
        profile: TinyH264Decoder.maxProfile,
        level: TinyH264Decoder.maxLevel,
    })
})

However, it will fail on some very old devices that doesn't support Baseline level 4 codec. You can retry without the codecOptions option.

const decoder = new TinyH264Decoder();
document.body.appendChild(decoder.element); // It draws frames onto `decoder.element`

videoPacketStream // from `@yume-chan/scrcpy`
    .pipeTo(decoder.writable)
    .catch(() => { });