streaming - 使用 OBS 和 ffmpeg 串流多个 RTMP IP 摄像机
问题描述
我在运行 CentOS 7 的 VPS 上使用 Nginx 和 RMTP 模块创建了一个流媒体服务器。我正在尝试使用 OBS 流式传输多个 IP 摄像机来广播流。我的问题是如何使用 nginx.conf 文件中的不同应用程序为每个摄像头创建多个 m3u8 流文件。我尝试使用多个 OBS 实例来实现这一点,但我的 CPU 能力已经耗尽。我发现通过使用 ffmpeg 可以流式传输多个流,但我不知道确切的命令。每台摄像机用于广播的比特率约为 512Kbps-1024Kbps。我的 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.123.123/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 但我需要一些命令帮助。任何帮助,将不胜感激。提前致谢。
解决方案
推荐阅读
- firebase - 如何将电话身份验证添加到现有用户帐户
- python - 非字符键的 UTF-8 编码
- javascript - 我正在尝试遍历一个数组并找到在属性中说过关键字的每个对象
- bash - 获取在特定时间范围内更改的所有文件
- c++ - 使用指数将十进制转换为二进制
- javascript - SVG Rotate 在 IE 上不起作用 - Codepen 在 chrome 上完美运行
- python-3.x - 如何调用列表的特定行进行操作
- r - 在 R 中,如何根据数据每行中的最大值进行过滤?
- hdp - 在 Atlas 实体之间添加关系的简单示例?
- php - 使用 get_page($id) 时有没有办法引用另一个域?