Jeykey

Jeykey

Live streaming technologies with Elixir / Phoenix

I’m currently doing some research about live streaming and live video (like Twitch, YouTube Live, etc.). There are a lot of different technologies and tools out there for implementing real time video & audio in the web and mobile.

I found WebRTC and originally thougth it was a good fit. But after learning the details, I found a lot of complications with things like TURN servers and the overall need for a lot of different servers and services. As far as I understand it, the sending client could actually be more demanded with more viewers which is a no-go for this type of application.
Looking for simpler solutions I found protocols like HLS and RTP but I found issues with delay and a lack of Elixir implementations for both of them.

Looking around I also found a tutorial using NodeJS and normal websockets, just sending the raw images in Base64 (or other encoding) over the websocket. I have some performance concerns about this, but I have no data to know how fast Websockets and more specifically Phoenix Channels perform.
Since I saw that UDP seems to be the better option, I looked into :gen_utp, but it seems like a lot of the inifrastructure would have to be implemented, since there aren’t any frameworks.

Does anybody have any experience using Elixir or Phoenix for video live streams could give me some advice?

First Post!

peck

peck

you may want to take a look at mux and their competitors. They’ve solved a lot of these problems and will let you focus on the goals of your product vs getting bogged down in the details of video streaming.

Also, be sure to do your math. Bandwidth gets very expensive very quickly with video at level of scale, you don’t want to be hit with a giant bill at the end of the month that your customers payments aren’t able to cover.

Most Liked

mat-hek

mat-hek

Membrane Core Team

Hi @Jeykey, Membrane has a pure elixir implementation of RTP - see the demo and we recently created a bunch of components for streaming via HLS. We’re now documenting and polishing them, so they should be available shortly :wink: We’re also preparing an article about building a Twitch-like app with Membrane, watch the membrane tag if you’re interested.

Whatever solution you end up with, definitely don’t send raw images, especially in base64, as it will generate huge traffic and won’t scale at all (maybe unless you have very low resolution and framerate)

10
Post #2
mat-hek

mat-hek

Membrane Core Team

I believe Twitch itself uses either DASH or HLS, and so does Youtube/Facebook live. That’s because of scaling - those protocols basically split the stream into small chunks and serve them via HTTP, so you can quite easily set up a CDN in between and handle thousands of viewers. But yes, that also introduces higher latency - usually about 10 seconds - and while I suppose you can get better, it is not going to be even close to RTP’s 200-500 milliseconds. If the lowest possible latency is required, the solution is to use RTP on both sides. I see two options there:

  1. Peer to peer - streamer sends directly to each viewer - can handle a few receivers and strains the sender, but is relatively easy to implement with WebRTC - requires only a signalling server, such as Membrane WebRTC server and JS clients
  2. RTP between streamer and server and RTP between server and each viewer - if you want to have browser clients you still need to use WebRTC, but this time via WebRTC gateway on the server. And this will not scale as easily as HLS/DASH.
mat-hek

mat-hek

Membrane Core Team

Well, that’s the article I was speaking of, it’s by my teammate and I reviewed it :stuck_out_tongue: So personally I think the approach is perfect :smiley: I posted about that in the membrane thread but it looks like it’s not visible enough there. @AstonJ can it be separated?

Last Post!

AstonJ

AstonJ

It can be moved to the Elixir Blog Posts thread here if you like, or, if you post a new thread in the backend blog posts category on devtalk.com you’ll can get a thread for it there and it will automatically get cross-posted here under your username :003:

This announcement has more details:

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement