我有hginx和rtmp模块。rtmp流工作正常,现在我想尝试hls流。
我的配置:
rtmp {
server {
listen 1935;
application myapp {
live on;
exec_pull /usr/bin/ffmpeg -i http://url-to-remote-webcam
-map 0 -codec:v copy rtmp://my-ip:1935/myapp/mystream.flv 2>>/tmp/ffmpeg-$name.log;
}
application myapp {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 5s;
}
}
}
http {
server {
listen 8080;
location /hls {
root /tmp;
}
}
}
尝试在vlc播放器中打开url http://my-ip:8080/hls/mystream.m3u8,但是出现了不能开放源代码的错误。
我能错过什么?
更新
我试着根据miknik的答案编辑配置。
rtmp {
server {
listen 1935;
application myapp {
live on;
exec_push ffmpeg -i http://url-to-remote-webcam -acodec copy -vcodec libx264 -vprofile baseline -g 10 -r 15 -s 640x360 -f flv rtmp://my-ip:1935/hls/mystream;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 5s;
}
}
}
http {
server {
listen 8080;
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
}
root /tmp;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
}
}
并尝试打开http://my-ip:8080/hls/mystream.m3u8
,但仍然有相同的错误。
在这里,来自nginx日志的错误:
2018/09/20 15:50:29 [error] 11406#11406: *2 open() "/tmp/hls/mystream.m3u8" failed (2: No such file or directory), client: client-ip, server: , request: "GET /hls/mystream.m3u8 HTTP/1.0", host: "server-ip:8080"
发布于 2018-09-12 17:59:11
首先,您的两个rtmp应用程序都称为myapp
。打电话给第二个hls
。
在myapp块中,您需要(可选地转换和)将流推到hls块。所以你需要这样的指令:
exec_push ffmpeg -i rtmp://127.0.0.1:1935/stream/$name -acodec copy -vcodec libx264 -vprofile baseline -g 10 -r 15 -s 640x360 -f flv rtmp://127.0.0.1:1935/hls/$name;
然后,在您的http块中,您需要位置块,如下所示:
location / {
try_files $uri $uri/ =404;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /var/www/test/stat;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
index index.m3u8 index.ts;
add_header Access-Control-Allow-Origin *;
}
这是值得包括的统计位置,因为它可能是非常有用的,因为它可能是非常有用的,为什么有些东西是不工作的,你期待它。
https://stackoverflow.com/questions/52291289
复制相似问题