Setting up video streaming on DigitalOcean’s premium CPU-optimized droplets can offer high performance for encoding, streaming, and handling multiple simultaneous connections. Below is a step-by-step guide to deploy a video streaming server using FFmpeg and Nginx with RTMP (Real-Time Messaging Protocol) module.
Step 1: Create a CPU-Optimized Droplet-
Log in to DigitalOcean:
- Go to your DigitalOcean dashboard.
-
Create a New Droplet:
- Click "Create" in the top right corner and select "Droplets".
- Choose an image (Ubuntu 22.04 LTS is recommended).
- Select a premium CPU-optimized droplet plan. For video streaming, you’ll need a plan with higher CPU and memory.
- Choose a data center region close to your audience.
- Add your SSH key for secure access.
- Click "Create Droplet".
-
Step 2: Access Your Droplet
-
SSH into Your Droplet:
- Open a terminal on your local machine.
-
Connect to your droplet using its IP address:
ssh root@your_droplet_ip
-
SSH into Your Droplet:
-
Update Your System:
sudo apt update sudo apt upgrade -y
-
Install Nginx and Dependencies:
sudo apt install -y build-essential libpcre3 libpcre3-dev libssl-dev zlib1g zlib1g-dev
-
Install FFmpeg:
sudo apt install -y ffmpeg
-
Download and Install Nginx with RTMP Module:
cd /usr/local/src sudo git clone https://github.com/arut/nginx-rtmp-module.git sudo wget http://nginx.org/download/nginx-1.20.1.tar.gz sudo tar -zxvf nginx-1.20.1.tar.gz cd nginx-1.20.1 sudo ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module sudo make sudo make install
-
Edit Nginx Configuration:
sudo nano /usr/local/nginx/conf/nginx.conf
-
Add RTMP Module Configuration:
Add the following at the end of the file:
rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; } } } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8080; server_name localhost; location / { root html; index index.html index.htm; } location /live { types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } alias /tmp; add_header Cache-Control no-cache; } } }
-
Start Nginx:
sudo /usr/local/nginx/sbin/nginx
-
Start Streaming with FFmpeg:
Replace
your_droplet_ip
with your droplet's IP address.ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac -f flv rtmp://your_droplet_ip/live/stream
-
Access the Stream:
Open a media player like VLC and open a network stream with the URL:
http://your_droplet_ip:8080/live/stream.m3u8
-
Install a Firewall:
sudo apt install ufw sudo ufw allow OpenSSH sudo ufw allow 8080/tcp sudo ufw allow 1935/tcp sudo ufw enable
-
Secure Nginx with SSL:
Use Let’s Encrypt to secure your server with SSL:
sudo apt install certbot sudo certbot certonly --standalone -d your_domain
-
Update Nginx Configuration for SSL:
Modify your Nginx config to include SSL settings:
server { listen 443 ssl; server_name your_domain; ssl_certificate /etc/letsencrypt/live/your_domain/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your_domain/privkey.pem; location /live { types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } alias /tmp; add_header Cache-Control no-cache; } }
By following these steps, you will have a high-performance video streaming server running on a CPU-optimized droplet on DigitalOcean. This setup ensures efficient video processing and streaming capabilities, ideal for handling a significant number of simultaneous connections.