【问题标题】:nginx rtmp exec logs but does not executenginx rtmp exec 记录但不执行
【发布时间】:2022-10-09 05:12:46
【问题描述】:

当我的流完成创建 ts 段时,有没有办法可以执行脚本?或者当用户连接并开始/停止查看流时?

NGINX RTMP EXEC Directives 说:“指定要在每个发布的流上执行的带有参数的外部命令。当发布停止时,该过程终止。二进制文件的完整路径应指定为第一个参数。没有关于这个过程应该做什么的假设。但是,此功能对于 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

【问题讨论】:

  • 我发现问题可以追溯到 6 年多到 2015 年,用户在使用 exec 指令时遇到问题。奇怪的是,有些人在没有明显原因的情况下可以正常工作。我重新编译。尝试减小我的 nginx.conf 的大小以查看是否可能存在冲突。我将其他指令进一步向上移动到 rtmp{} 和 server{},并将 hls 指令移动到 application{}。这些都没有改善。我拼错了 exec 指令和 nginx 反对,这使我相信它们已编译但没有响应。我怀疑它是一个适用于特定 linux 风格的功能,只是不适用于我的 AWS AMI2。

标签: nginx exec nginx-rtmp


【解决方案1】:

似乎 nginx rtmp 中的 exec 功能与操作流特别相关,因此无法使用脚本工作。如果我用 ffmpeg 命令替换我的命令,nginx rtmp 将执行 ffmpeg。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多