目前,我的解决方案正在运行,但仅作为RTMP,我可以使用URL完美地观看我的视频流:
rtmp://X.X.X.X:1935/show/name
但是问题是我的使用WebOS的LG Smart Tv不支持RTMP,我真的很想在那儿播放我的视频流。我现在可以看到的唯一解决方案是使用HLS。使用HLS,一切也都可以正常工作,但是我需要先执行ffmpeg命令,然后才能在电视中打开HLS流,否则它将不会创建在电视上显示该流所需的文件。
因此,我的目标是在不手动触发RTMP端点或FFMPEG的情况下将流用作HLS。
我真的很为此挣扎,浪费了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;
}
}
}
感谢您的时间;)
答案 0 :(得分:0)
请尝试以下类似方法:
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;
}
}
}