Home  >  Article  >  Backend Development  >  ngnix development (5) Convert rtmp live stream to hls live stream

ngnix development (5) Convert rtmp live stream to hls live stream

WBOY
WBOYOriginal
2016-07-29 09:01:133168browse

1:修改/usr/local/nginx/conf/ngnix.conf,红色字体为添加内容。

#rtmp直播配置
   server {
    listen 1936;
    chunk_size 4000;
      application  live {
            live on;
 
            hls on;            

    hls_path /usr/local/nginx/html/multimedia/hls/live;

            hls_fragment 2s;
            hls_playlist_length 6s;

       }
      }


    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
#creates the http-location for our full-resolution (desktop) HLS stream - "http://my-ip/hls/my-stream-key/index.m3u8"      
location /livehls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias /usr/local/nginx/html/multimedia/hls/live;
add_header Cache-Control no-cache;
}

.......

}

2: 通过ffmpeg  发送 live流

ffmpeg -re -i test.mp4 -vcodec libx264 -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://yourseverIp:1936/live/show

注意:推送的视频格式最好h264,某些格式不支持的话,导致ts文件无法生成。

3:播放链接:http://yourseverIp:1936/live/show.m3u8

1:)live为application的名字,此处由conf定义。

2:)show为直播流的名字,此处由ffmpeg定义。

我在vlc中直接播放此链接。完成!!!

以上就介绍了ngnix开发(五)将rtmp直播流转换成hls直播流,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn