How I live-streamed to multiple platforms simultaneously with a low latency of under 7 seconds!
Tags: octograd2020
Published: 2020-05-22 05:41:43

[Comment]: # (All of this is placeholder text. Use this format or any other format of your choosing to best describe your project and experience.)

[Note]: # (If you used the GitHub Student Developer Pack on your project, add the "#githubsdp" tag above. We’d also love to know which services you used and how you used it!)

## Live.ly

In a world where interactions are primarily focused on virtualisation and life has inclined towards the audio and video streaming services, there is hardly anyone who hasn't ever used a streaming service. People all across the world are connected with each other by using the internet. Unlike other video on demand streaming services or video broadcasts, real time interaction has become crucial for both streamers and their audiences. Today, popular livestreams capture thousands of users and covers everything like press conferences, political protests, stage concerts, TV shows, etc. To guarantee a no-lag video streaming, one must make sure that the latency is low and transmission rate is least possible. This is a significant challenge in today’s world for streamers.

So one day, while I was at a college event, I started to live-stream the event on my Instagram account but since I was a club member as well, the club wanted me to do a YouTube live. During that moment, I realised that how about I build a service which allows someone to go live on multiple platforms at once. The project that was a result of this achieved a low client latency of less than 7 seconds. 

In streaming audio and video, the moving information is a stream of data, going out from a server. The decoder is a stand- alone player or a plugin that works as a part of the Web browser. The server, the information stream and decoder work together to let people watch live or prerecorded broadcasts. The program playing the streaming file discards the data as we watch. A full copy of the file never exists on the user’s computer.

The most commonly used protocol for streaming live content is UDP because we don't care about lost packets, if a second of video is lost, the viewers want to see the next, more recent content rather than seeing something which happened 2 seconds before. Since UDP is a connectionless & fast protocol, we prefer it over TCP. 

Popular platforms like Facebook, Youtube and Twitch offer unique RTMP streaming urls with private keys to each user. The live stream can be pushed to these urls and then it can be displayed on these platforms.

So let's see how the project works: A person uses an RTMP live streaming app on his phone like NabiLive (for iOS) which generates a RTMP stream of the live content. This stream is sent to our media server (nginx). Then, the user opens our website where he inputs the urls mentioned above and clicks on 'begin streaming'. Now, the nginx config file get's appended with the new urls and the stream generated by the mobile app is now pushed on to these urls after being transcoded to multiple bitrates in order to maintain separate files for separate video qualities. 
 
The best part is that we only need to push the highest bit rate stream and the media server is capable to transcode it to multiple bitrates on the fly. The m3u8 and ts files are sent from our media server to S3.

## Technologies Used

I used html, css & javascript for the front end and php for the backend. Nginx was used as the server so each time a new output link was added, the nginx config file was updated. 

The link to my GitHub repo for the project is:

{% github https://github.com/preritpathak/lively %}
[Note]: # (Our markdown editor supports pretty embeds. If you're sharing a GitHub repo, try this syntax: `{% github link_to_your_repo %}`)

[Final Note]: # (CONGRATULATIONS!!! You are amazing!)