我打算在Debian机器上使用nginx+rtmp module
重播网络摄像头。当我重播一个凸轮时,它的工作原理不错且流畅,但是占用了太多的CPU:
这是我的配置:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
}
rtmp_auto_push on;
rtmp {
live on;
hls on;
hls_fragment 5s;
respawn_timeout 15s;
chunk_size 8192;
server {
listen 1935;
application cam1 {
hls_path /tmp/cam1;
}
exec_static /usr/bin/ffmpeg -i http://cam-ip:8080/flv?login=user&channelid=channalid&password=pass&count=0
-acodec copy -vcodec libx264 -vprofile baseline -f flv rtmp://server-ip/cam1/stream;
}
}
http {
server {
listen 8080;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location stat.xsl {
root /stat;
}
location / {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp/;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
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;
}
}
}
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
}
我在配置中添加了12个网络摄像头后,在查看cam时出现了严重的延迟。以及100%的CPU使用率:
为什么在htop中有这么多ffmpeg进程?
为什么要占用这么多CPU?