当我尝试使用nginx + nginx-http-flv-module + flv.js播放摄像机中的视频时,发生了错误,但是使用VLC播放可以正常工作。
登录nginx:
flv live: app args MUST be specified, client: 192.168.89.1, server: myserver, request: "GET /live.html HTTP/1.1", host: "192.168.89.134:8080"
一些关键配置,
nginx.conf:
http{
...
server{
...
location /live {
flv_live on;
chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response
add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
}
}
}
rtmp {
server {
listen 1935;
server_name 192.168.89.134;
application myapp {
live on;
gop_cache on;
}
}
}
ffmpeg命令:
ffmpeg -f avfoundation -s 1280x720 -r 30 -i 0 -f flv rtmp://192.168.89.134:1935/myapp/test
VLC网络网址:
http://192.168.89.134:8080/live?port=1935&app=myapp&stream=test
带有flv.js的HTML:
if (flvjs.isSupported()) {
var videoElement = document.getElementById('videoElement');
var flvPlayer = flvjs.createPlayer({
type: 'flv',
'isLive': true,
url: 'http://192.168.89.134:8080/live?port=1935&app=myapp&stream=test'
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
flvPlayer.play();
}
谁能告诉我为什么基于您的经验?谢谢。