nginx build a simple live broadcast server

1. Download module (nginx-rtmp-module)

1 cd /data/nginx
2 yum install git3 git clone https://github.com/arut/nginx-rtmp-module.git

2. Install nginx:

1 yum install gcc make pcre-devel openssl-devel 
2 wget http://nginx.org/download/nginx-1.15.0.tar.gz 
3 tar xf nginx-1.15.0.tar.gz
4 cd nginx-1.15.0
5 ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module     
6 make && make install

3. Modify the nginx configuration file

1  rtmp {      
 2      server {   
 3          listen 1935 ;          #listening port    
 4 chunk_size 4000 ; #packet size, default 4096, the larger the value, the lower the CPU, cannot be less than 128
 5  
6          application hls {#rtmp push stream request path 
 7              live on;             #Turn on live
 8  hls on; #Turn on hls
 9              hls_path / usr / share / nginx / html / hls; #rtmp push stream file storage path, read and write permissions
 10              hls_fragment 5s; #each TS file contains 5 seconds Video content
 11         }   
12     }   
13 } 

4. Push flow

ffmpeg push stream

推流:
ffmpeg -re -i  /path/file.mp4   -vcodec copy - acodec copy -f flv rtmp://192.168.4.11:1935/hls

obs push stream

Download the obs software, click settings, URL: rtmp: // IP: 1935 / hls, stream name: room number

Create a new VLC local video, then start streaming, there are multiple sources of streaming (local video, images, external devices), view the files in the / usr / local / nginx / html / hls directory

5. Watch live broadcast (pull stream)

Play with a browser that supports HTML5 (Microsoft Edge)

cat /usr/local/nginx/html/test.html 
<video>
    <source src="http://192.168.4.11/hls/test.m3u8"/>
    <p class="warning">Your browser does not support HTML5 video.</p>
</video>

Play with software VLC

Stream address: http: // 192.168.4.11/hls/test.m3u8

 

Guess you like

Origin www.cnblogs.com/wuhg/p/12731597.html