- Joined
- Jun 9, 2020
Every day, the censorship gets stronger. We may be granted some respite, but centralized services are eventually wont to fail. For social media, forums, etc., federation offers an acceptable solution, but for livestreaming the expenses are simply too great to shoulder.
The only technology that's worked thus far for file-sharing (in spite of all its flaws) is BitTorrent (https://en.wikipedia.org/wiki/BitTorrent). If you have been living under a rock, BitTorrent allows you to share files without a centralized server by forcing the people who download ("leeching") to also upload ("seed"). Nobody has ever come up with a good replacement for BitTorrent without these flaws (leaks IP, needs special software).
Could we do something similar for livestreaming?
Technical
The most common livestream protocol today is HLS. HLS is used everywhere because it allows you to re-use ordinary HTTP CDN infrastructure. HLS replaced RTMP, which required specialized software to properly stream.
HLS works like this:
In other words, there's two servers. A main server, that just gets you a list of say 100 video files (last few minutes), and a CDN server, that just serves random files it's fed by the backend.
The main server is (comparatively) cheap to run, and the CDN can be run on commodity infrastructure.
So here's the idea I had: instead of having the playlist contain links to mp4 files, you link to torrents. A torrent costs ~nothing to create, and is fast to download in large numbers. Sure, it'll take a few seconds, but that'll just manifest as stream delay.
(It might even be faster if it's well optimized, since there's less intermediate servers)
Implementation - client
This idea seems extremely simple, which leads me to wonder why anyone hasn't done it yet.
I don't want to rewrite the HLS spec or make a whole new video player, so something that works in VLC would be ideal. You'd need to point VLC to an URL that has a m3u feed with (HTTP) links to mp4 files.
My first idea was to have a local torrent client, and have the remote server feed you the feed, and VLC queries the HTTP links in there, and those point to something like localhost:1234/torrent_hash. On localhost:1234, there's some torrent client that GETs whatever you point it to and feeds it over HTTP.
This has some problems:
The application would poll for a new HLS stream, as well as a list of all torrents for the stream. It would get the infohash of the torrent, and associate it in a map that goes infohash -> metainfo.
Then, when localhost:1234/infohash is queried, it already has the metainfo and can start downloading.
This means scrolling would work properly.
(In the distant future, you could get the HLS over DHT/gossip too, but it would be a lot of work for a first draft, I think Tor or something would be good enough)
You could also have some mechanism where it starts to download new torrents as they come in, as a cache.
This still doesn't seem that hard, though. It seems seductively easy.
You could add chat trivially, just add an IRC client.
Implementation - server
This is actually much easier.
What I worry about
This isn't gonna be a drop-in replacement for Twitch, just as uTorrent isn't a drop-in replacement for MegaUpload. To wit:
What might go well
Livestreaming isn't limited to politics stuff. As I see it, there'll be three main audiences of this software:
Again, this would not have the mass appeal of Dlive/Trovo, at least not initially, but it's better than nothing, it would be extremely robust and provide an absolutely certain "lowest level" below which you'd never cross, and you could use it as a backbone to build more robust services (like in the soccer example above)
Questions
What I want to know is this:
The only technology that's worked thus far for file-sharing (in spite of all its flaws) is BitTorrent (https://en.wikipedia.org/wiki/BitTorrent). If you have been living under a rock, BitTorrent allows you to share files without a centralized server by forcing the people who download ("leeching") to also upload ("seed"). Nobody has ever come up with a good replacement for BitTorrent without these flaws (leaks IP, needs special software).
Could we do something similar for livestreaming?
Technical
The most common livestream protocol today is HLS. HLS is used everywhere because it allows you to re-use ordinary HTTP CDN infrastructure. HLS replaced RTMP, which required specialized software to properly stream.
HLS works like this:
- Every second, check the stream URL for a list of videos (m3u playlist)
- Each video file is like 4 seconds long. There's like a thousand video files in a hour long stream.
- Every few seconds, a new video file gets added to the end of the playlist
- The file server with the videos doesn't need any special adaptations for livestreaming
In other words, there's two servers. A main server, that just gets you a list of say 100 video files (last few minutes), and a CDN server, that just serves random files it's fed by the backend.
The main server is (comparatively) cheap to run, and the CDN can be run on commodity infrastructure.
So here's the idea I had: instead of having the playlist contain links to mp4 files, you link to torrents. A torrent costs ~nothing to create, and is fast to download in large numbers. Sure, it'll take a few seconds, but that'll just manifest as stream delay.
(It might even be faster if it's well optimized, since there's less intermediate servers)
Implementation - client
This idea seems extremely simple, which leads me to wonder why anyone hasn't done it yet.
I don't want to rewrite the HLS spec or make a whole new video player, so something that works in VLC would be ideal. You'd need to point VLC to an URL that has a m3u feed with (HTTP) links to mp4 files.
My first idea was to have a local torrent client, and have the remote server feed you the feed, and VLC queries the HTTP links in there, and those point to something like localhost:1234/torrent_hash. On localhost:1234, there's some torrent client that GETs whatever you point it to and feeds it over HTTP.
This has some problems:
- You have to hardcode the port:IP pair
- Anyone who can make GET requests to localhost can make you download arbitrary torrents
The application would poll for a new HLS stream, as well as a list of all torrents for the stream. It would get the infohash of the torrent, and associate it in a map that goes infohash -> metainfo.
Then, when localhost:1234/infohash is queried, it already has the metainfo and can start downloading.
This means scrolling would work properly.
(In the distant future, you could get the HLS over DHT/gossip too, but it would be a lot of work for a first draft, I think Tor or something would be good enough)
You could also have some mechanism where it starts to download new torrents as they come in, as a cache.
This still doesn't seem that hard, though. It seems seductively easy.
You could add chat trivially, just add an IRC client.
Implementation - server
This is actually much easier.
- Provide RTMP sink
- Transcode RTMP to HLS
- When a HLS chunk is done, run mktorrent and:
- Load the torrent file into the torrent client
- Push the torrent file out to the users
- Add the infohash to the m3u8
What I worry about
This isn't gonna be a drop-in replacement for Twitch, just as uTorrent isn't a drop-in replacement for MegaUpload. To wit:
- You'll need to install software. (Web-based torrent is shit; BitChute gave up on it totally, and PeerTube just falls back to the CDN)
- You'll leak your IP. In practice, people download lots of torrents and nobody seems to care. People don't care about their IP being exposed for coomer stuff, even.
- Performance and stream delay might be bad.
- I don't see how you're going to support adaptive live streaming, where you vary the quality. I see two choices:
- Users download qualities they don't actually want to seed them (inefficient)
- You do some encoding black magic to get something like a progressive JPEG with the 16kib chunks (hard?)
- This won't work very well on mobile (but not impossible)
What might go well
Livestreaming isn't limited to politics stuff. As I see it, there'll be three main audiences of this software:
- Political extremists, who can't get hosting anywhere else.
- Sports fans, who want to illegally stream sports.
- Coomers.
Again, this would not have the mass appeal of Dlive/Trovo, at least not initially, but it's better than nothing, it would be extremely robust and provide an absolutely certain "lowest level" below which you'd never cross, and you could use it as a backbone to build more robust services (like in the soccer example above)
Questions
What I want to know is this:
- Did any projects try desktop-based torrent livestreaming?
- Why did it fail?
- https://github.com/pldubouilh/live-torrent - Here's a WebTorrent PoC
- How low can you get the starting latency of a torrent?
- How many specific hacks (pre-seeding peers, pushing torrents over WS, preloading torrents) are you going to need for OK performance?
- How much software will you be able to re-use?
- What's the potential to get a good ecosystem to grow around this, that isn't just political lunatics?
- Would this software enable people who are otherwise totally blacklisted (i.e. very exciting political figures) to get a "new voice"?
- Would you be interested in trying this, once I put a beta release together?
Last edited: