Arun Raghavan

Extremely pithy tagline here

Some of you might have been following all the brouhaha over Popcorn Time. I won’t get into the arguments that can be made for and against at the moment.

While poking around at what it was that Popcorn Time was doing, I stumbled upon peerflix, a Node.js-based application that takes a .torrent file that points to one big video file, and presents that as an HTTP stream. It has its own BitTorrent implementation where it prioritises early chunks of the file so that it is possible to start watching the video before the entire file has been downloaded. It also seeds the file while the video is being watched locally.

Seeing as I was at the GStreamer Hackfest in Munich when this came up in discussions, it seemed topical to have a GStreamer element to wrap this neat bit of functionality. Thus was peerflixsrc born. This is a simple source element that takes a URI to a torrent file (something like torrent+http://archive.org/some/video.torrent), fires up peerflix in the background, and provides the data from the corresponding HTTP stream. Conveniently enough, this can be launched using playbin or Totem (hinting at the possibilities of what can come next!). Here’s what it looks likeā€¦

Screenshot of Totem playing a torrent file directly using peerflixsrc

Screenshot of Totem playing a torrent file directly using peerflixsrc

The code is available now. To use it, build this copy of gst-plugins-bad using your favourite way, make sure you have peerflix installed (sudo npm install -g peerflix), and you’re good to go.

This is not quite mature enough to go into upstream GStreamer. The ugliest part is firing up a Node.js server to make this work, not the least because managing child processes on Linux is not the prettiest code you can write. Maybe someone wants to look at rewriting the torrent bits from peerflix in C? There don’t seem to be any decent C-based libraries for this out there, though.

In the mean time, enjoy this, and comments / patches welcome!


Comments
Harvey Specter
Posted at 12:04 am March 20, 2014
j
Reply
Author

Have a look at http://jordic.com/btcat/ it does something like it using libtorrent. Its written in python but it might be a better base for a C-based implementatoin

Harvey Specter
Posted at 1:08 pm March 20, 2014
Alexander Larsson
Reply
Author

Managing child processes, made easy: https://developer.gnome.org/gio/unstable/GSubprocess.html

    Harvey Specter
    Posted at 12:32 pm March 25, 2014
    Arun
    Reply
    Author

    Nice! Will switch over to that shortly. Do you know if there’s an elegant way to also make sure the child goes away if the parent does? I’ve seen the PR_SET_PDEATHSIG, but that goes away if the child does a fork(), which defeats the purpose, somewhat.

Harvey Specter
Posted at 5:44 pm March 20, 2014
Alexandre Franke
Reply
Author

Tribler has done the get-first-chunks-first-to-stream-over-torrent trick for a while now (I now for sure that it was already working in 2007) and it’s written in Python (with a C core/lib?). You may find that less ugly than the Node.js way.

Harvey Specter
Posted at 11:12 pm April 29, 2014
John McHugh
Reply
Author

Good work so far. Would be neat to have something akin to open torrent bundles that gnome could utilize in videos and music to curate createive commons media.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>