Frontend Development 13 min read

Bilibili's WasmPlayer: WebAssembly-based HEVC Soft Decoding Solution for Web Video Playback

Bilibili’s WasmPlayer is a WebAssembly‑based HEVC software decoder that runs entirely in C/C++, handling demuxing, decoding, resampling and A/V sync on worker threads, using SIMD, AudioWorklet and OffscreenCanvas to deliver smooth 4K 60 fps web video playback with reduced bandwidth and CPU load.

Bilibili Tech
Bilibili Tech
Bilibili Tech
Bilibili's WasmPlayer: WebAssembly-based HEVC Soft Decoding Solution for Web Video Playback

This article introduces Bilibili's self-developed WasmPlayer, a WebAssembly-based HEVC software decoder for web video playback. HEVC (High Efficiency Video Coding) is a more efficient video compression standard than AVC, capable of reducing file size by 50% while maintaining the same quality, enabling smooth playback at half the bandwidth.

The development background explains that Bilibili prioritized user experience and began exploring HEVC encoding to further reduce playback stuttering. While HEVC is mainly used on mobile devices, web browsers have limited support. Thanks to Chrome's WebAssembly support (v57+) and SharedArrayBuffer (v68+), Bilibili developed a WebAssembly-based software decoder for HEVC playback.

The technical architecture uses a custom <bwp-video> tag via Shadow DOM API and implements BWP MSE API. The solution integrates seamlessly with existing web player architectures with minimal cost. Unlike typical WebAssembly solutions that only implement decoding in WebAssembly while keeping IO control and rendering in JavaScript, WasmPlayer implements a complete player in C/C++ including demuxing, audio/video decoding, resampling, and A/V sync control in the WebAssembly layer.

The article details the fully asynchronous rendering architecture that moves all heavy operations to worker threads, keeping the main thread free for user interaction. Audio rendering uses AudioWorkletProcessor (Chrome v64+) running on a dedicated thread, while video rendering uses WebGL + OffscreenCanvas for off-screen rendering on worker threads, achieving 20%+ frame rate improvement and better stability.

Performance optimization includes SIMD support (Chrome v91+), achieving 4K 60fps real-time HEVC decoding with up to 100fps decoding capability. The SIMD version is 2x faster than non-SIMD, reducing CPU load by 27-70% on mid-range laptops and 31-58% on high-end desktops.

The playback strategy section explains how Bilibili handles AV1, HEVC, and AVC encoding formats, with automatic selection based on bitrate, resolution, and anomaly detection. WasmPlayer启用策略 includes hardware requirements (minimum 4 CPU cores), automatic seamless degradation to AVC on stuttering, and automatic disabling during persistent issues.

performance optimizationWebAssemblyOffscreenCanvasSIMDmultimediavideo-playerHEVCAudioWorkletSoft Decodingvideo decoding
Bilibili Tech
Written by

Bilibili Tech

Provides introductions and tutorials on Bilibili-related technologies.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.