mafintosh / torrent-stream

The low level streaming torrent engine that peerflix uses
MIT License
1.94k stars 228 forks source link

Is it possible to pipe the createReadStream to a web browser video element? #94

Open pgeske opened 9 years ago

pgeske commented 9 years ago

Hello, In the first example under the Usage section, I am wondering if it is possible to pipe the created stream to an HTML5 element, so that I would be able to stream the torrent file on a web browser. Webtorrent provides an example of this here (https://github.com/feross/webtorrent/blob/master/examples/browser-stream-to-video.js), however such an approach (piping to the created video element) does not work with torrent-stream.

Could someone provide me with a basic example of piping the stream to an HTML5 element?

asapach commented 9 years ago

Unlike WebTorrent, torrent-stream is a back-end component, not a front-end one, and as such, it doesn't run in a browser. You'll need something like peerflix to stream video over http.

feross commented 9 years ago

torrent-stream doesn't run in the browser, but you can use peerflix to start an http server and open the url in a browser or use it in a <video> tag.

jaruba commented 9 years ago

I recently made an NPAPI Plugin for the browser that might help you in your endeavour: Powder NPAPI Plugin

The plugin includes a portable version of node and peerflix and sends the parsed peerflix output from the command line in a JSON object back to the page (so you can call peerflix directly from the page), a simple example of it doing so can be found on the github page.

Then you'll have to use the streaming link from peerflix in your html5 video tag, and if it's a compatible format, like ".mp4" it will play it, otherwise, you'll have to also use a web video plugin, such as WebChimera, VLC Web Plugin or DivX Web Player to play any video format. (or, ofc, modify peerflix to also transcode with ffmpeg, but this is very resource intensive and not recommended)

I can make an example of this plugin streaming to WebChimera if you think that would help. But keep in mind that it would require 2 plugins installed on the user's PC (although they could be merged into only one installer) and that NPAPI plugins will be deprecated in Chrome from September this year.