3 min read

Create Live Streaming (RTMP) Server on Ubuntu 24.04

Introduction
In this guide, we will set up an Ubuntu 24.04 server to receive input from Open Broadcaster Software (OBS) and output it in HTTP Live Streaming (HLS) format. Additionally, we will integrate AWS CloudFront for content delivery (CDN) and assign sub-domains for seamless streaming.

For example:

RTMP Link (Input): rtmp://live-in.example.com/live/stream

Stream Key: stream

HLS (Output): https://live.example.com/hls/stream.m3u8

  1. Setup Docker to Ubuntu Server (EC2)
    After launching your instance, we need to log in into our new server using SSH client.
ssh -i "YourKey.pem" ubuntu@SERVER_IP

After login, you need to update packages

sudo apt update && sudo apt upgrade -y

Set Timezone (Asia/Kolkata):


sudo timedatectl set-timezone Asia/Kolkata && sudo timedatectl


Install Required Dependencies

sudo apt install -y ca-certificates curl gnupg


Add Docker’s Official GPG Key


sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo tee /etc/apt/keyrings/docker.asc > /dev/null
sudo chmod a+r /etc/apt/keyrings/docker.asc
Add Docker Repository
echo "deb [signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify Docker Installation

sudo systemctl enable --now docker
sudo docker --version


Run Docker Without sudo (Optional)

sudo usermod -aG docker $USER
newgrp docker


Test Docker


docker run hello-world
  1. Run the nginx-live-stream Docker Image
    To start the Nginx Live Stream server, follow the steps below:

Pull the Docker image:

docker pull sannjayy/nginx-live-stream:latest


For more information about the Docker image, click here.

Run the Docker container

Run in CLI

docker run -p 1935:1935 -p 8080:8080 sannjayy/nginx-live-stream

Run in Detached Mode

docker run -d -p 1935:1935 -p 8080:8080 sannjayy/nginx-live-stream:latest
  1. Start Streaming
    Using ffmpeg:
    To start streaming using ffmpeg, execute the command below:
ffmpeg -re -i video.mp4 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ar 44100 -f flv rtmp://SERVER-IP:1935/live/test


Rename the video.mp4 and replace SERVER-IP with your server’s IP address.

Testing the video feed Embedded Player
To access the embedded player, navigate to the following URL in your browser:

http://SERVER-IP:8080/player/?url=http://SERVER-IP:8080/hls/test.m3u8
  1. Setup CloudFront for content delivery (CDN)
    Create distribution
    Origin domain

Public IPv4 DNS of the EC2 Instance
Protocol

HTTP Only

8080

Enable Origin Shield

No
Compress objects automatically

No
Viewer protocol policy

HTTP and HTTPS
Allowed HTTP methods

GET, HEAD
Restrict viewer access

No
Cache key and origin requests
Legacy cache settings

Headers: None

Query strings: None

Cookies: None

Object caching

Customize

Minimum TTL: 0

Maximum TTL: 0

Default TTL: 0

Your setup is now complete. You have successfully configured an Ubuntu 24.04 server to receive input from Open Broadcaster Software (OBS) and output it in HTTP Live Streaming (HLS) format. Additionally, you have integrated AWS CloudFront for content delivery (CDN) and assigned sub-domains for seamless streaming.

  1. Custom Domain Setup (Optional)
    In your DNS Server (Route 53 or Cloudflare) add these records.
Record Name Record Type Value
live-in A [Server_IP]
live CNAME d1234abcd.cloudfront.net

Your custom domain setup is now complete. You can access your streaming server using your custom domain (e.g., https://live.example.com/hls/stream.m3u8).

To test the stream: https://sanjaysikdar.dev/tools/video-stream-tester

Troubleshoot
Before starting, ensure that the following inbound rules are allowed in your firewall settings:

Custom TCP 8080

Custom TCP 1935

TCP 22 for SSH access https://read.sanjaysikdar.dev/live-streaming-rtmp-server-on-ubuntu-2404

Sanjay Sikdar · Feb 13, 2025
https://read.sanjaysikdar.dev/live-streaming-rtmp-server-on-ubuntu-2404

Leave a Reply

AI assistant