用nginx实现http-flv推流
时间: 2023-05-23 08:04:56 浏览: 372
A:
要使用nginx实现http-flv推流,需要按照以下步骤:
1.安装nginx和rtmp-module
首先需要安装nginx和rtmp-module。可以参考以下资料进行下载和安装。
nginx官网:http://nginx.org/
rtmp-module官网:https://github.com/arut/nginx-rtmp-module
2.配置nginx.conf文件
在nginx.conf文件中,需要添加以下配置信息。其中,flv、live和stream是自定义的,可以根据需要修改。
rtmp {
server {
listen 1935; #监听端口
chunk_size 4096; #设置chunk_size大小
application flv {
live on; #启用直播模式
allow publish all; #允许推流
deny play all; #禁止播放
push_reconnect off; #关闭推流断开重连
hls off; #关闭hls
flv_metadata on; #开启flv的metadata信息
wait_key on; #开启wait_key
exec_pull ffmpeg -i rtmp://xxxx/$app/$name -vcodec libx264 -vprofile baseline -s 720x576 -acodec libfaac -ar 44100 -f flv rtmp://xxxx/flv/$name; #开启转码功能,实现兼容性
notify_method get; #推流成功后,请求指定地址
notify_update http://xxxx/stream/$app/$name;
}
}
}
http {
server {
listen 80; #监听端口
location /live {
flv_live on; #开启http-flv推流
chunked_transfer_encoding on; #开启chunked传输
add_header 'Access-Control-Allow-Origin' '*'; #跨域
add_header 'Allow' 'GET, POST, OPTIONS'; #允许的http方法
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; #允许跨域的方法
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept'; #允许跨域的请求头
}
}
}
3.启动nginx
将修改后的nginx.conf文件保存,使用以下命令启动nginx。
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
4.推流
使用推流软件(如OBS)等工具,将视频流推送到rtmp://localhost/flv/{stream_name}的地址,即可在http://localhost/live/{stream_name}.flv,通过http-flv协议播放推送的视频流。
阅读全文
相关推荐
















