首页  >  文章  >  后端开发  >  ngnix开发(五)将rtmp直播流转换成hls直播流

ngnix开发(五)将rtmp直播流转换成hls直播流

WBOY
WBOY原创
2016-07-29 09:01:133135浏览

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教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn