当我的流完成创建ts段时,有没有办法执行脚本?或者当用户连接并开始/停止查看流时?
NGINX RTMP EXEC指令说:指定要在发布的每个流上执行的带有参数的外部命令。当发布停止时,进程将终止。二进制文件的完整路径应指定为第一个参数。对于这个过程应该做什么没有任何假设。但是,这个功能对于ffmpeg流代码转换非常有用";。
我尝试过,但无法执行任何exec指令,/var/log/nginx/error_log中也没有任何错误。有人能提供建议吗?
注意,我使用用户apache,而不是用户nginx来实现我未来的目标——然而apache没有在系统上运行,所以用户名应该不是问题。
我使用以下方法从windows笔记本电脑流式传输到远程服务器:ffmpeg.exe -re -i movie.mp4 -c:v libx264 -b:a 128k -crf 23 -strict experimental -f flv rtmp://x.x.x.x:1604/live/teststream
这很有效-我在服务器上得到了index.m3u8和ts文件填充/efsr/5/nginx/hls/teststream。
我的所有exec指令都调用相同的脚本(仅用于测试目的):
$ ls -ld /efsr/5/nginx/scripts/nginx_publish_done.sh
-rwxr-xr-x 1 apache apache 66 Jul 12 20:01 /efsr/5/nginx/scripts/nginx_publish_done.sh
而且。。。
$ cat /efsr/5/nginx/scripts/nginx_publish_done.sh
#!/usr/bin/bash
/bin/date >> /tmp/nginx_publish_done.tmp
exit 0
我的nginx.conf文件没有错误:
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
尽管配置文件中没有错误报告,但我已经尝试了各种语法调用,例如,以下语法都没有执行我的脚本:
exec_publish bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 1";
exec_publish bash -c /efsr/5/nginx/scripts/nginx_publish_done.sh 1;
exec_publish /efsr/5/nginx/scripts/nginx_publish_done.sh 1;
我的nginx.conf如下:
worker_processes auto;
user apache;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
root /var/www/nginx/hls;
location / {
index index.html index.htm index.m3u8;
}
}
}
# RTMP configuration
rtmp {
# Sets maximum number of connections for rtmp engine. Off by default.
max_connections 200;
# LIVE
live on;
# meta on|copy|off : on=receive reconstructed meta data : copy=copy meta data
meta copy;
# interleave on|off : on=audio and video data is transmitted on the same RTMP chunk stream.
interleave on;
# wait_key on|off : on=Makes video stream start with a key frame
wait_key on;
# idle_streams on|off : If disabled nginx-rtmp prevents subscribers from connecting to
# idle/nonexistent live streams and disconnects all subscribers when stream publisher disconnects
idle_streams on;
# disable consuming the stream from nginx as rtmp
#deny play all;
# HLS
# Turn on HLS
hls on;
# Sets HLS playlist type specified in X-PLAYLIST-TYPE playlist directive.
# options: live|event
hls_type live;
# Sets HLS playlist and fragment directory.
# If the directory does not exist it will be created.
hls_path /efsr/5/nginx/hls;
# Sets HLS fragment length. Defaults to 5 seconds.
hls_fragment 10s;
# Sets HLS playlist length. Defaults to 30 seconds. (can set to 10m for 10mins)
hls_playlist_length 1440m;
# Sets fragment naming mode: sequential|timestamp|system
hls_fragment_naming system;
# Toggles HLS nested mode. In this mode a subdirectory of hls_path is
# created for each stream. Playlist and fragments are created in that
# subdirectory. Default is off.
hls_nested on;
# HLS continuous mode. In this mode HLS sequence number is started
# from where it stopped last time. Old fragments are kept.
hls_continuous on;
server {
listen 1604; # Listen (standard RTMP port 1935)
# Default is 4096. Prior value was 8192
# maximum chunk size for stream multiplexing.
# Bigger value = lower CPU
chunk_size 4096;
# buffer length. Default is 1000ms
buflen 8000ms;
application live {
live on;
wait_key on;
wait_video on;
publish_notify on;
exec_publish bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 1";
exec_publish_done bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 2";
exec_play bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 3";
exec_play_done bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 4";
exec_pull bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 5";
exec_push bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 6";
exec_record_done bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 7";
exec_static bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 8";
# live view off|all|audio|video;
record off;
record_path /var/www/nginx/record;
record_suffix -%F.flv;
record_unique on;
record_interval 15m;
record_max_size 100M;
}
}
}
构建nginx 时的版本和配置参数
# nginx -V nginx version: nginx/1.23.1 (CentOS) built by gcc 7.3.1 20180712 (Red Hat 7.3.1-15) (GCC) built with OpenSSL 1.1.1q 5 Jul 2022 TLS SNI support enabled configure arguments: --prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=apache --group=apache --build=CentOS --add-module=/usr/local/src/nginx-rtmp-module --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module --with-stream_ssl_preread_module --with-compat --with-pcre --with-pcre-jit --with-zlib=/usr/local/src/zlib-1.2.12 --with-openssl=/usr/local/src/openssl-1.1.1q --with-openssl-opt=no-nextprotoneg --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-debug
看来nginx rtmp中的exec功能与操作流特别相关,因此使用脚本无法工作。如果我用ffmpeg命令替换我的命令,nginx-rtp将执行ffmpeg。