|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+jsmpeg
|
|
|
2
|
+==========
|
|
|
3
|
+
|
|
|
4
|
+#### An MPEG1 Video Decoder in JavaScript ####
|
|
|
5
|
+
|
|
|
6
|
+jsmpeg is a MPEG1 Decoder, written in JavaScript. It's "hand ported", i.e. not compiled with
|
|
|
7
|
+emscripten or similar. This will probably make it obsolete with the advent of asmjs.
|
|
|
8
|
+
|
|
|
9
|
+Some demos and more info: (phoboslab.org/log/2013/05/mpeg1-video-decoder-in-javascript)[http://www.phoboslab.org/log/2013/05/mpeg1-video-decoder-in-javascript]
|
|
|
10
|
+
|
|
|
11
|
+
|
|
|
12
|
+### Usage ###
|
|
|
13
|
+
|
|
|
14
|
+```javascript
|
|
|
15
|
+// Synopsis: var player = new jsmpeg(urlToFile, options);
|
|
|
16
|
+// The 'options' argument and all of its properties is optional. If no canvas element
|
|
|
17
|
+// is given, jsmpeg will create its own, to be accessed at .canvas
|
|
|
18
|
+
|
|
|
19
|
+// Example:
|
|
|
20
|
+var canvas = document.getElementById('videoCanvas');
|
|
|
21
|
+var player = new jsmpeg('file.mpeg', {canvas: canvas, autoplay: true, loop: true});
|
|
|
22
|
+
|
|
|
23
|
+player.pause();
|
|
|
24
|
+player.play();
|
|
|
25
|
+player.stops();
|
|
|
26
|
+
|
|
|
27
|
+
|
|
|
28
|
+// An 'onload' callback can be specified in the 'options' argument
|
|
|
29
|
+var mpegLoaded = function( player ) {
|
|
|
30
|
+ console.log('Loaded', player);
|
|
|
31
|
+}
|
|
|
32
|
+var player = new jsmpeg('file.mpeg', {onload:mpegLoaded});
|
|
|
33
|
+
|
|
|
34
|
+// If you don't use 'autoplay' and don't explicitly call .play(), you can get individual
|
|
|
35
|
+// video frames (a canvas element) like so:
|
|
|
36
|
+var frame = null;
|
|
|
37
|
+while( (frame = player.nextFrame()) ) {
|
|
|
38
|
+ someOtherCanvasContext.drawImage(frame, 0, 0);
|
|
|
39
|
+}
|
|
|
40
|
+```
|
|
|
41
|
+
|
|
|
42
|
+### Limitations ###
|
|
|
43
|
+
|
|
|
44
|
+- Playback can only start when the file is fully loaded. I'm waiting for chunked XHR with ArrayBuffers to arrive in browsers.
|
|
|
45
|
+- MPEG files with B-Frames look weird - frames are not reordered. This should be relatively easy
|
|
|
46
|
+to fix, but most encoders seem to not use B-Frames at all by default.
|
|
|
47
|
+- The width of the MPEG video has to be a multiple of 2.
|
|
|
48
|
+- Only raw MPEG video streams are supported. The decoder hates Stream Packet Headers in between
|
|
|
49
|
+macroblocks.
|
|
|
50
|
+
|
|
|
51
|
+You can use (FFmpeg)[http://www.ffmpeg.org/] to encode videos in a suited format. This will crop
|
|
|
52
|
+the size to a multiple of 2, omit B-Frames and force a raw video stream:
|
|
|
53
|
+
|
|
|
54
|
+```
|
|
|
55
|
+ffmpeg -i in.mp4 -f mpeg1video -vf "crop=iw-mod(iw\,2):ih-mod(ih\,2)" -b 0 out.mpg
|
|
|
56
|
+```
|