ソースを参照

Added info about streaming

Dominic Szablewski 12 年 前
コミット
53e06a0270
共有1 個のファイルを変更した37 個の追加1 個の削除を含む
  1. 37 1
      README.md

+ 37 - 1
README.md ファイルの表示

@@ -39,9 +39,45 @@ while( (frame = player.nextFrame()) ) {
39 39
 }
40 40
 ```
41 41
 
42
+### Live Streaming ###
43
+
44
+jsmpeg supports streaming live video through WebSockets. You can use ffmpeg and a nodejs server to serve the MPEG video. See this [blog post](http://phoboslab.org/log/2013/09/html5-live-video-streaming-via-websockets) for the details of setting up a server. Also have a look at the `stream-server.js` and `stream-example.html`.
45
+
46
+To configure jsmpeg to connect to the stream server, simply pass a WebSocket connection instead of a filename to the constructor:
47
+
48
+```javascript
49
+// Setup the WebSocket connection and start the player
50
+var client = new WebSocket( 'ws://example.com:8084/' );
51
+var player = new jsmpeg(client, {canvas:canvas});
52
+```
53
+
54
+##Stream Recording##
55
+
56
+To record an MPEG stream clientside in the browser jsmpeg provides the `.startRecording(cb)` and `.stopRecording()` methods. `.stopRecording()` returns a `Blob` object that can be used to create a download link.
57
+
58
+```javascript
59
+player.startRecording(function(player){
60
+	// Called when recording really starts; usually 
61
+	// when the next intra frame is received
62
+});
63
+
64
+// ...
65
+
66
+// Stop recording and create a download link
67
+var blob = player.stopRecording();
68
+
69
+var filename = 'jsmpeg-recording.mpg';
70
+var a = document.getElementById('downloadLink');
71
+a.innerHTML = filename;
72
+a.download = fileName;
73
+a.href = window.URL.createObjectURL(blob);
74
+```
75
+
76
+
77
+
42 78
 ### Limitations ###
43 79
 
44
-- Playback can only start when the file is fully loaded. I'm waiting for chunked XHR with ArrayBuffers to arrive in browsers.
80
+- Playback can only start when the file is fully loaded (when not using streamin). I'm waiting for chunked XHR with ArrayBuffers to arrive in browsers.
45 81
 - MPEG files with B-Frames look weird - frames are not reordered. This should be relatively easy
46 82
 to fix, but most encoders seem to not use B-Frames at all by default.
47 83
 - The width of the MPEG video has to be a multiple of 2.