我在运行 CentOS 7 的 VPS 上使用 Nginx 和 RMTP 模块创建了一个流媒体服务器。我正尝试使用 OBS 流式传输多个 IP 摄像机以广播该流。我的问题是如何使用 nginx.conf 文件中的不同应用程序为每个摄像机创建多个 m3u8 流文件。我尝试使用多个 OBS 实例来实现这一点,但我的 CPU 能力耗尽了。我发现使用 ffmpeg 可以流式传输多个流,但我不知道命令。我的 nginx.conf 如下:
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
# Define the Application
application camera1 {
live on;
exec ffmpeg -i rtmp://123.123.123.123/folder/$name -vcodec libx264 -vprofile
baseline -x264opts keyint=40 -acodec aac -strict -2 -f flv rtmp://123.123.123.123/hls/$name;
# Turn on HLS
hls on;
hls_path /mnt/hls/camera1;
hls_fragment 3s;
hls_playlist_length 60s;
# disable consuming the stream from nginx as rtmp
# deny play all;
}
application camera2 {
live on;
exec ffmpeg -i rtmp://123.123.123.123./$app/$name -vcodec libx264 -vprofile
baseline -x264opts keyint=40 -acodec aac -strict -2 -f flv rtmp://123.123.1231.23/hls/$name;
# Turn on HLS
hls on;
hls_path /mnt/hls/camera2;
hls_fragment 3s;
hls_playlist_length 60s;
# disable consuming the stream from nginx as rtmp
# deny play all;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
aio on;
directio 512;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server {
listen 80;
server_name 123.123.123.123;
location / {
root /var/www/html;
index index.html index.htm;
}
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/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
}
}
}
使用 2 个具有不同流名称的 OBS 实例,我可以同时流式传输 2 个摄像头,但我想流式传输超过 50 个摄像头,而使用这种方法是不可能的。我认为可以使用 ffmpeg 来完成。RTSP 流的格式是 rtsp://username:password@hostname:port,但我希望在命令方面得到一些帮助。任何帮助都将不胜感激。提前致谢。