Introducing peerflixsrc

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+, 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!


Add yours →

  1. Have a look at it does something like it using libtorrent. Its written in python but it might be a better base for a C-based implementatoin

  2. Alexander Larsson

    March 20, 2014 — 1:08 pm

    Managing child processes, made easy:

    • 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.

  3. 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.

  4. 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.

  5. saurabh shabdik

    August 5, 2014 — 7:04 am

    I am just an Ubuntu user not an expert. Looking for help. I have started watching movies with torrent flix, torrent video player. It saves video in temp folder. I searched and get these command or argument to change the folder. –f or –path ( change buffer file path ) Please tell me how to press the argument or command Thanks in advance

Leave a Reply