Nginx builds a streaming media server to achieve on-demand and live broadcast

Nginx builds a streaming media server to achieve on-demand and live broadcast tutorial - source code file - click to download

Preface
Streaming media refers to a form of media that transmits audio, video and multimedia files in a streaming manner over a network. Compared with the network playback form of watching after downloading, the typical feature of streaming media is to compress continuous audio and video information and put it on the network server. Users can watch while downloading without waiting for the entire file to be downloaded. Due to the superiority of streaming media technology, this technology is widely used in video-on-demand, video conferencing, distance education, telemedicine and online live broadcast systems. As a symbol of a new generation of Internet applications, streaming media technology has developed rapidly in recent years.
The streaming media server is the core system of streaming media applications and the key platform for operators to provide video services to users. The main function of the streaming media server is to collect, cache, schedule, transmit and play the streaming media content. The main performance of the streaming media application system depends on the performance and service quality of the media server. Therefore, the streaming media server is the basis of the streaming media application system, and it is also the most important part.

Environment centos7 nginx

1. Download all required packages
Package description:
nginx-1.13.12.tar.gz //nginx
nginx-rtmp-module-master.zip //Let nginx support rtmp/hls protocol
ngx_cache_purge.zip // The module that clears the cache
nginx_mod_h264_streaming-2.2.7.tar.gz //Let nginx support flv, mp4 streaming playback
pcre-8.39.tar.gz //pcre
zlib-1.2.8.tar.gz //zlib
EV screen recording_3.9 .5.0.exe //Screen recording software-pushing
vlc16216.exe //video playback software-pulling
nginx.conf //nginx configuration file

2. Install the nginx dependency package
yum install gcc gcc-c++ openssl openssl-devel cyrus-sasl-md5

3. Upload the required packages to centos7
nginx-1.13.12.tar.gz
nginx-rtmp-module-master.zip
ngx_cache_purge .zip
nginx_mod_h264_streaming-2.2.7.tar.gz
pcre-8.39.tar.gz
zlib-1.2.8.tar.gz

4. Unzip all packages
tar -zxvf nginx-1.13.12.tar.gz
unzip nginx-rtmp- module-master.zip
unzip ngx_cache_purge.zip
tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
tar -zxvf pcre-8.39.tar.gz
tar -zxvf pcre-8.39.tar.gz

5. Enter nginx-rtmp-module- After master.zip is decompressed, in the nginx-rtmp-module-master directory, comment out the if statement where r->zero_in_uri is located in the ngx_http_streaming_module.c file.

6. Install nginx
into nginx-1.13.12.tar.gzp After decompression, nginx-1.13 .12 directory execute the following command
./configure --prefix=/usr/local/nginx/ --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8 --add-module=../nginx -rtmp-module-master --add-module=../ngx_cache_purge-master --add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with -http_gzip_static_module --with-http_flv_module After
the execution is completed, modify the Makefile file under objs in the nginx installation directory, delete -Werror and
execute make && make install

7. Check whether
/usr/local/nginx/sbin/nginx -V is successfully executed ,If it is the following information, it means the installation is successful
nginx version: nginx/1.13.12
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx/ --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8 --add-module=../nginx -rtmp-module-master --add-module=../ngx_cache_purge-master --add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with -http_gzip_static_module --with-http_flv_module

8. Copy the nginx-rtmp-module-master directory to the nginx site and rename it to nginx-rtmp-module
cp -rf nginx-rtmp-module-master /usr/local/nginx/ html/
mv /usr/local/nginx/html/nginx-rtmp-module-master /usr/local/nginx/html/nginx-rtmp-module

9. Create VOD and Live site directories
// VOD
mkdir -p /usr/ local/nginx/html/media/

//Live
mkdir -p /tmp/hls/

10. Replace the nginx configuration file
//make a backup
cp nginx.conf nginx.conf_bak
Replace the nginx configuration with the following configuration (you can use the nginx.conf in the installation package to replace it directly)

worker_processes 2;
error_log    /usr/local/nginx/logs/error.log;
pid        /usr/local/nginx/logs/nginx.pid;
events {     use epoll;     worker_connections 51200; } rtmp {     server {         listen 1935;         chunk_size 4096;         application live {             live on;             record off;         }         #video on demand         application media {             play /usr/local/nginx/html/;         }         application hls {             live on;             hls on;             hls_path /tmp/hls/;



   
















        }
    }
}
 
http {     include        mime.types;     default_type application/octet-stream;     sendfile        on;     keepalive_timeout 65;     gzip on;     server {         listen        80;         server_name localhost;         #charset koi8-r;         #access_log logs/host.access.log main;         location / {             root    html;             index index.html index.htm;         }         location ~ \.flv$ {             root /usr/local/nginx/html/media/;                flv;         }


















        location ~ \.mp4$ {             root /usr/local/nginx/html/media/;             mp4;         }         location /stat {             rtmp_stat all;             rtmp_stat_stylesheet stat.xsl;         }         location /stat.xsl {             root /usr/local/nginx/html/nginx-rtmp-module/;         }         location /hls {             # Serve HLS fragments             types {                 application/vnd.apple.mpegurl m3u8;                 video/mp2t ts;             }             root /tmp;             add_header Cache-Control no-cache;         }



















        location /dash {             # Serve DASH fragments             root /tmp;             add_header Cache-Control no-cache;         }         error_page    500 502 503 504 /50x.html;         location = /50x.html {             root    html;         }     } }










11.开启远程访问端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=1935/tcp --permanent
结果返回success,则设置成功
firewall-cmd --reload
结果返回success,则设置成功

12.点播测试
上传一个mp4或者flv的视频文件到/usr/local/nginx/html/media/目录下
安装安装包中的视频播放软件(其他视频播放软件也可以的)vlc16216.exe
打开VLC media player -> 媒体 -> 打开网络串流
在网络协议中输入:http://服务器IP/视频文件名  例如:http://blog.kz38.cn/test.flv,点击播放,即可看到点播视频内容



13.直播测试
安装录屏软件(他视频播放软件也可以的)EV录屏_3.9.5.0.exe
打开EV录屏 -> 设置 -> 直播设置
在串流地址中输入: rtmp://服务器IP/hls/直播名称(可任意命名) 例如:rtmp://blog.kz38.cn/hls/test

选择在线直播,开始录屏

打开浏览器 访问http://服务器IP/stat  例如:http://blog.kz38.cn/stat,可以看都正在推送的直播流

打开VLC media player -> 媒体 -> 打开网络串流
在网络协议中输入:rtmp://服务器IP/hls/直播名称 例如:rtmp://blog.kz38.cn/hls/test ,点击播放,即可看到直播视频内容

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324501359&siteId=291194637