Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A JavaScript H.264 decoder.
C JavaScript Logos C++ Objective-C HTML Other
Latest commit 173511c @soliton4 soliton4 Merge pull request #88 from emersion/readme-codeblock
Adds a codeblock to README
Failed to load latest commit information.
Decoder removed require
Player background color
templates updated templates
AUTHORS thank you @oneam
LICENSE Licensing
README.markdown Adds codeblock



A JavaScript H.264 decoder.

View a Live Demo:

The video player first needs to download the entire video before it can start playing, thus appearing to be a bit slow at first, so have patience. You can start the video by clicking on each player. The top left player runs on the main thread, the remaining players run in background worker threads.

Use a example node app as template:

Technical info

The demo is Android's H.264 decoder compiled with Emscripten to JavaScript, then further optimized with Google's JavaScript closure compiler and further optimized by hand to use WebGL.

Building the demo:

Install and configure Emscripten (
The current version of Broadway was built with emscripten 1.29.0

The code for the demo is in the Decoder folder, to build it run the python script. (Requires at least python 2.7)

Encoding Video

The decoder expects an .mp4 file and does not support weighted prediction for P-frames and CABAC entropy encoding. To create such bitstreams use ffmpeg and x264 with the following command line options:

ffmpeg -y -i sourceFile -r 30000/1001 -b:a 2M -bt 4M -vcodec libx264 -pass 1 -coder 0 -bf 0 -flags -loop -wpredp 0 -an targetFile.mp4


Player.js, Decoder.js and YUVWebGLCanvas.js all have a unified module definition.
You can use them as plain js files or with common.js / AMD


var p = new Player({

p.canvas; // the canvas - put it where you want it

p.decode(<h264 data>);


useWorker true / false
decode in a worker thread

path to Decoder.js. Only neccessary when using worker. defaults to "Decoder.js"

webgl true / "auto" / false
use webgl. defaults to "auto"

size { width: , height: }
initial size of the canvas. canvas will resize after video starts streaming.



refers to the canvas element.


decode ()

feed the decoder with h264 stream data.


var p = new Decoder({

p.onPictureDecoded; // override with a callback function

p.decode(<h264 data>);


rgb true / false
if true will convert the image to rgb. sligtly slower.


onPictureDecoded callback function(, width, height)

will be called for each frame.


decode ()

feed the decoder with h264 stream data.

Real World Uses of Broadway.js

Something went wrong with that request. Please try again.