Setting up HLS streaming media server on ubuntu16.04

Source: Internet
Author: User
Tags git clone

1.Distributor Id:ubuntu
Description:ubuntu 16.04.3 LTS
release:16.04
Codename:xenial

2.Linux 4.4.0-89-generic #112-ubuntu SMP Mon Jul 19:38:41 UTC x86_64 x86_64 x86_64 gnu/linux

mkdir ~/working

Switch to the ~/working directory

CD ~/working

Get Nginx Source code:

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

Extract

Tar xvf nginx-1.13.4.tar.gz

Get the latest nginx-rtmp source code

git clone https://github.com/arut/nginx-rtmp-module.git

Switch to Nginx directory

CD nginx-1.13.4

Configuration

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

Compile and install Nginx with NGINX-RTMP module

Make

sudo make install

Installing Nginx init scripts

Get nginx init script

wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx

Copy the script to the/etc/init.d/directory

sudo cp nginx/etc/init.d/

Modify Permissions

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

Using UPDATE-RC.D for startup item Management

sudo update-rc.d nginx defaults

Create a directory structure

sudo Mkdir/hls

sudo mkdir/hls/mobile

sudo mkdir/hls/live

sudo mkdir/video_recordings

sudo chmod-r 777/video_recordings

Configure Nginx

Back up the original Nginx configuration file

sudo cp/usr/local/nginx/conf/nginx.conf/usr/local/nginx/conf/nginx.conf.back

sudo gedit/usr/local/nginx/conf/nginx.conf

Add the following to/usr/local/nginx/conf/nginx.conf

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.1.104: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.1.104: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-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.1.104;

#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 what stats on viewers on we 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;
}
}
}

!!记得将本地内网地址换成你实际使用的哦!!

Start Nginx Service

sudo service nginx start

Installing FFmpeg

sudo apt-get install FFmpeg

Push Flow Start

Ffmpeg-re-i test.mp4-vcodec libx264-acodec aac-f flv rtmp://localhost/mobile/haha/* Pushes local video file Test.mp4 transcoding to local server */

Open VLC player on the native side

Input stream address Rtmp://localhost/mobile/haha can watch video, but local play some lag, network play more card, waiting for optimization ... (not to be continued)

Setting up HLS streaming media server on ubuntu16.04

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.