Set up the hls Streaming Media Server on ubuntu16.04 and ubuntu16.04hls

Source: Internet
Author: User

Set up the hls Streaming Media Server on ubuntu16.04 and ubuntu16.04hls

 

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 31 19:38:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

 

Mkdir ~ /Working

Switch ~ /Working directory

Cd ~ /Working

Obtain nginx source code:

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

Extract

Tar xvf nginx-1.13.4.tar.gz

Obtain the latest nginx-rtmp source code

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

Switch to the 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

Install nginx Initialization Script

Get nginx Initialization 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

Use update-rc.d for startup Item Management

Sudo update-rc.d nginx defaults

Create 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 content 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 10 s;

# Creates the downsampled or "trans-rated" mobile video stream as a 400 kbps, 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 400 k-maxrate 400 k-bufsize 400 k-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 10 s;
}

# 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.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 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;
}
}
}

!! Remember to replace the Local intranet address with what you actually use !!

Start the nginx Service

Sudo service nginx start

Install ffmpeg

Sudo apt-get install ffmpeg

Start streaming

Ffmpeg-re-I test.mp4-vcodec libx264-acodec aac-f flv rtmp: // localhost/mobile/haha/* Push the audio video file test.mp4 to the local server */

Enable vlc player on the Local Computer

Enter the stream address rtmp: // localhost/mobile/haha to watch the video. However, the local playback is slow, and the network playback is even slower, waiting for optimization... (To be continued)

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.