![使用 OBS 和 ffmpeg 流式传输多个 RTMP IP 摄像机](https://linux22.com/image/1616270/%E4%BD%BF%E7%94%A8%20OBS%20%E5%92%8C%20ffmpeg%20%E6%B5%81%E5%BC%8F%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%20RTMP%20IP%20%E6%91%84%E5%83%8F%E6%9C%BA.png)
我在运行 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,但我希望在命令方面得到一些帮助。任何帮助都将不胜感激。提前致谢。