在这一点上,我的解决方案是有效的,但仅作为RTMP,我可以使用URL完美地观看我的流:
rtmp://X.X.X.X:1935/show/name但问题是,我的LG智能电视,使用WebOS不支持RTMP,我真的很想在那里播放我的流。我现在能看到的唯一解决方案就是使用HLS。使用HLS也一切正常,但在电视中打开HLS流之前,我需要执行ffmpeg命令,否则它将不会创建在我的电视上显示流所需的文件。
因此,我的目标是将流作为HLS提供,而不必手动触发RTMP端点或FFMPEG。
我真的很努力,花了3天的时间才让它工作起来:
http
{
location /hls
{
# Disable cache
add_header Cache-Control no-cache;
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
}
}
}
rtmp {
server {
listen 1935;
chunk_size 4000;
buflen 5s;
application show {
live on;
exec_pull ffmpeg -re -i http://stream-coming.com/$name.ts -c:v libx264 -preset faster -pix_fmt yuv420p -c:a aac -f flv rtmp://localhost/show/$name;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
}
}}
感谢您的宝贵时间;)
发布于 2018-11-21 06:44:49
试试下面这样的代码:
rtmp {
server {
listen 1935;
application show {
live on;
exec_push ffmpeg -re -i rtmp://stream-coming.com:1935/$name.ts
-c:v libx264 -preset faster -pix_fmt yuv420p -c:a aac -f flv rtmp://localhost:1935/hls/$name;
exec_kill_signal term;
}
application hls {
# Turn on HLS
live on;
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 12;
# disable consuming the stream from nginx as rtmp
allow publish 127.0.0.1;
deny play all;
}
}
}https://stackoverflow.com/questions/52919354
复制相似问题