Portal Home > Knowledgebase > Frequently Asked Questions > How to setup streaming server

How to setup streaming server

Hello and welcome to hostshield.net, today i am going to show you how to setup your own streaming server.

First of all order an ubuntu vps from the following link: https://www.hostshield.net/billing/cart.php?gid=4

After you receive your details connect to it via SSH

 

Start by installing the following command:

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

 

Make a stream directory and go to it:

mkdir ~/stream

cd ~/stream

 

Download Nginx and rtmp source:

wget http://nginx.org/download/nginx-1.7.5.tar.gz

wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

 

Install the zip package:

sudo apt-get install unzip

 

Unzip the package:

tar -zxvf nginx-1.7.5.tar.gz

unzip master.zip

 

Change directory to nginx:

cd nginx-1.7.5

 

Compile it:

./configure --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx-rtmp-module-master

make

sudo make install

 

Install nginx script:

sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx

sudo chmod +x /etc/init.d/nginx

sudo update-rc.d nginx defaults

 

Start and stop nginx:

sudo service nginx start

sudo service nginx stop

 

Installing FFMPEG:

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next

sudo apt-get update

sudo apt-get install ffmpeg

 

Configuring nginx:

sudo nano /usr/local/nginx/conf/nginx.conf

 

Delete everything inside the nginx.conf and replace with the following:

worker_processes  1;

error_log  logs/error.log debug;

events {

worker_connections  1024;

}

rtmp {

server {

listen 1935;

allow play all;

 

#creates our "live" full-resolution HLS videostream from our incoming encoder stream and tells where to put the HLS video manifest and video fragments

application live {

allow play all;

live on;

record all;

record_path /video_recordings;

record_unique on;

hls on;

hls_nested on;

hls_path /HLS/live;

hls_fragment 10s;

 

#creates the downsampled or "trans-rated" mobile video stream as a 400kbps, 480x360 sized video

exec ffmpeg -i rtmp://192.168.254.178:1935/$app/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -s 480x360 -b:v 400k maxrate 400k -bufsize 400k -threads 0 -r 30 -f flv rtmp://192.168.254.178:1935/mobile/$;

}

 

#creates our "mobile" lower-resolution HLS videostream from the ffmpeg-created stream and tells where to put the HLS video manifest and video fragments

application mobile {

allow play all;

live on;

hls on;

hls_nested on;

hls_path /HLS/mobile;

hls_fragment 10s;

}

 

#allows you to play your recordings of your live streams using a URL like "rtmp://my-ip:1935/vod/filename.flv"

application vod {

play /video_recordings;

}

}

}

 

 

http {

include       mime.types;

default_type  application/octet-stream;

 

server {

listen 80;

server_name 192.168.254.178;

 

#creates the http-location for our full-resolution (desktop) HLS stream - "http://my-ip/live/my-stream-key/index.m3u8"      

location /live {

types {

application/vnd.apple.mpegurl m3u8;

}

alias /HLS/live;

add_header Cache-Control no-cache;

}

 

#creates the http-location for our mobile-device HLS stream - "http://my-ip/mobile/my-stream-key/index.m3u8"        

location /mobile {

types {

application/vnd.apple.mpegurl m3u8;

}

alias /HLS/mobile;

add_header Cache-Control no-cache;

}   

 

#allows us to see how stats on viewers on our Nginx site using a URL like: "http://my-ip/stats"     

location /stats {

stub_status;

}

 

#allows us to host some webpages which can show our videos: "http://my-ip/my-page.html"     

location / {

root   html;

index  index.html index.htm;

}   

}

}


Also Read