trunk/3rdparty/srs-docs/blog/2022-04-09-Oryx-Tutorial.md
Streaming video is very popular in a variety of industries, and there are many tutorials for building a media server, using SRS or NGINX-RTMP that host stream does not rely on other service providers.
<!--truncate-->But if we want to build a online video streaming service, it's much more than only a media server:
Literally it's not just a media server, and seems a bit complicated, right? Yep and No!
In this tutorial, you will learn how to set-up a video streaming service, supports publishing by browser without a plugin that is converting WebRTC to HLS, to deliver low latency (about 300ms) video streaming using SRT, and to secure the service by authentication. Furthermore, this solution is open source and very easy to get it done, via even 1-Click.
To complete this guide, you need:
This guide will use placeholder your_public_ipv4 and your_domain_name throughout for streaming URLs.
Please replace them with your own IP address or domain name.
Sign up for an AWS account and sign in to AWS Lightsail. Next, click the
Create instance button. Select the Linux/Unix platform and the OS Only blueprint. Finally, choose
Ubuntu 20.04 LTS as the instance image.
Next, click the Add launch script button and input the following script that will be executed to install
the Oryx once the instance has been created.
Please input the following script:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/ossrs/oryx/HEAD/scripts/lightsail.sh)"
Note: You can also access the instance and run the script manually. Please search for instructions on how to log in to a Lightsail instance.
Next, choose the instance plan, select the 2vCPUs 1GB plan or a higher one, and click on Create instance.
Once the instance has been established, access the Networking tab and click Attach static IP to keep it
from changing. Within IPv4 Firewall, press the Add rule option, add an All protocols rule and click
the Create button:
Now, the Oryx is created! Open http://your_public_ipv4/mgmt/ in the browser, click the Submit button
to set-up the administrator password for the first time.
If you prefer not to utilize AWS Lightsail, have an alternative VPS, or even a virtual machine or personal computer locally available, highly recommend using Docker for a simple and efficient way to run Oryx on VPS using just one command:
docker run --restart always -d -it --name oryx -v $HOME/data:/data \
-p 80:2022 -p 443:2443 -p 1935:1935 -p 8000:8000/udp -p 10080:10080/udp \
ossrs/oryx:5
After the Oryx is created, open http://your_public_ipv4/mgmt/ in the browser, click the Submit button
to set-up the administrator password for the first time.
You can use DigitalOcean droplet to run Oryx just one-click. A droplet is a simple and scalable virtual machine of DigitalOcean. An SRS Droplet is a droplet with Oryx installed, to power your video streaming service.
You could create an SRS Droplet by clicking here,
then click the Create SRS Droplet button, set-up the droplet Region and Size, then click Create Droplet
button at the bottom.
Note: Recommend the size
2vCPUs 2GBor slightly larger.
After the Oryx is created, open http://your_public_ipv4/mgmt/ in the browser, click the Submit button
to set-up the administrator password for the first time.
OBS is more simple to use, and SRS provides guide for OBS, please click Scenarios > Streaming > RTMP: OBS or vMix
or open URL http://your_public_ipv4/mgmt/en/routers-scenario?tab=live with Server and StreamKey for OBS,
please copy these config and paste to OBS:
Note: There is also a guide for publishing streams by FFmpeg and WebRTC, however, it's a bit complex for WebRTC, and we will talk about it later.
After publishing an RTMP stream to SRS, you're able to play the stream by HTTP-FLV or HLS, by clicking the H5 player link, or play the URL by VLC.
Note: The latency of VLC is huge, so please use ffplay to play the RTMP or HTTP-FLV if you wanna a low latency live streaming.
Now we have finished the basic live streaming publishing and playing, note that the Stream Key contains a
secret which is used for authentication. Without this secret, SRS will deny the publisher, so only people
who know about the secret could publish an RTMP stream.
While for players, the URL is public and no secret thing, because generally we don't need to do authentication
for players. However, SRS is planned to support more authentication algorithms, including token for players,
or limits for number of connections, or disconnecting connections if they exceed a period of duration.
WebRTC or H5 is very convenient for users to share their camera, by just opening a H5 URL, to start live streaming like what OBS does. Please follow secure SRS with let's encrypt tutorial.
Because WebRTC requires HTTPS, so you need a fully registered domain name, you could purchase a domain
name on Namecheap or GoDaddy, however we will use
placeholder your_domain_name throughout this tutorial.
When you get a domain name, make sure a DNS record set-up for your server, please add an A record with
your_domain_name pointing to your server public IP address that is your_public_ipv4 as we said, see
Domains and DNS.
Now please switch to System / HTTPS / Let's Encrypt and enter your_domain_name, then click Submit
button to request a free SSL cert from Let's Encrypt:
When the HTTPS is ready, please open the URL https://your_domain_name/mgmt to access Scenarios > Streaming > WebRTC: WHIP Browser
and open the URL to publish using WebRTC:
Remark: Please note that the website and stream URLs have changed to HTTPS, both HTTPS-FLV, HLS and WebRTC.
The bellow is a demo for publishing by WebRTC and playing by HTTP-FLV or HLS:
WebRTC is a bit more complex than RTMP or HLS, but using the feature by SRS, it's also very simple to set-up the HTTPS website and WebRTC signaling API, and the demo pages for WebRTC publisher and player are also very simple to use.
For RTMP/FLV, the streaming latency is about 3~5s, while 5~10s for HLS. Which protocol to use if we want to
build a low latency live streaming service, say, less than 1s?
WebRTC? No! It's too complicated, and few devices support WebRTC. WHIP is a possible choice for live streaming using WebRTC, but it's not a RFC right now(at 2022). It might take a long time to apply WebRTC to the live streaming industry, especially if we get other choices, SRT and RIST etc.
Note: Whatever, Oryx allows you to use WebRTC for live streaming, to publish by WebRTC and play by RTMP/HLS/WebRTC.
It's also very easy to use SRT, by clicking Scenarios > Streaming > SRT: OBS or vMix, the guide is use
OBS to publish SRT stream, and play by ffplay. The latency of OBS+ffplay is about 300ms, the bellow is
a lower solution, by vMix+ffplay:
Note: The end-to-end latency of SRT is 200ms to 500ms, good enough! Well, WebRTC is about 50ms to 300ms latency. WebRTC is even lower than SRT, but WebRTC also introduces more pause events and the streaming is not smooth as SRT.
SRT is supported by a lot of devices of the broadcasting industry, and softwares like OBS/vMix also support SRT, so it's actually the most stable and easy way to get low latency live streaming.
Note that H5 does not support SRT, so you can't use Chrome to play a SRT stream, however, Oryx will convert SRT to HTTP-FLV/HLS to ensure compability with general live streaming.
Oryx also supports restreaming to other platforms, by forking multiple FFmpeg processes, each process for a stream. It's a long story, so let's discuss it in a new tutorial.
Well DVR is another story, DVR means we convert live streaming to VoD files, so we must save the VoD files to a cloud storage. So we're developing to support more cloud storage now.
We're also considering to integrate a CMS to Oryx, to allow users to publish the live streaming rooms, or VoD files like a vlog, etc.
Oryx is a single node video streaming service, but SRS is a media server that supports clusters, like Origin Cluster, RTMP Edge Cluster and even HLS Edge Cluster. The HLS Edge Cluster is based on NGINX, and SRS could work well with NGINX, we will publish more tutorials about this topic if you wanna.
At SRS, our goal is to establish a non-profit, open-source community dedicated to creating an all-in-one, out-of-the-box, open-source video solution for live streaming and WebRTC online services.
Additionally, we offer a Cloud service for those who prefer to use cloud service instead of building from scratch. Our cloud service features global network acceleration, enhanced congestion control algorithms, client SDKs for all platforms, and some free quota.
To learn more about our cloud service, click here.
In this tutorial, you build a video streaming service only by 1-Click, but with powerful features like authentication, SRT and WebRTC etc. If you have further questions about SRS, the wiki is a good place to start.
If you'd like to discuss with SRS, you are welcome to discord.