gpt4 book ai didi

ffmpeg - Nginx RTMP 拉取到 HLS 流

转载 作者:行者123 更新时间:2023-12-04 04:11:38 26 4
gpt4 key购买 nike

我已按照本指南设置 RTMP 到 HLS 流 - https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/

RTMP 流式传输工作得很好,但出于某种原因,我无法让 HLS 链接到现有的 RTMP 服务器。我正在使用 OBS 流式传输到 RTMP,它设置为在 x264 上,据我所知,音频的默认编解码器是 AAC,所以我不确定为什么它没有接收到它。

当前的 Nginx.conf

worker_processes  auto;
events {
worker_connections 1024;
}

# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;

# Define the Application
application show {
live on;
pull rtmp://localhost:1935/stream/test;
# 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 video on demand for mp4 files
application vod {
play /mnt/mp4s;
}

# RTMP stream using OBS
application stream {
live on;
}

}
}

http {
sendfile off;
tcp_nopush on;
aio on;
directio 512;
default_type application/octet-stream;

server {
listen 8080;

location / {
# 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/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}

root /mnt/;
}
}
}

我已经尝试将该配置中的 rtmp 链接也更改为内部和外部 IP,因为它可以访问。我测试了从网络上的另一台计算机观看 rtmp 以确认它可以正常工作。我想避免使用 ffmpeg 进行转码,因为服务器没有那种能力。

最佳答案

所以我整理了一下。基本上我一直在寻找的是在不需要转码的情况下将 RTMP 转换为 HLS。如果其他人看到了这个并且需要它,那么它非常简单,但是,您确实需要 ffmpeg 来实现它。您基本上告诉 ffmpeg 将流传递给 HLS,并且由于 OBS 已经采用正确的视频/音频格式,因此它将毫无问题地接受它。我使用的命令是

ffmpeg -re -i rtmp://localhost:1935/stream/test -codec copy -f flv /mnt/hls/stream.m3u8

这样做对我的 CPU 几乎没有影响,这正是我所需要的。

关于ffmpeg - Nginx RTMP 拉取到 HLS 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61626844/

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