gpt4 book ai didi

Nginx RTMP/HLS - 流式传输到 ffmpeg 并输出 HLS

转载 作者:行者123 更新时间:2023-12-04 23:24:41 27 4
gpt4 key购买 nike

此时我的解决方案正在运行,但仅作为 RTMP,我可以使用 URL 完美地观看我的流:

rtmp://X.X.X.X:1935/show/name

但问题是我使用 WebOS 的 LG 智能电视不支持 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;
}
}

}

谢谢你的时间 ;)

最佳答案

尝试这样的事情:

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;
}
}
}

关于Nginx RTMP/HLS - 流式传输到 ffmpeg 并输出 HLS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52919354/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com