arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.46k stars 3.51k forks source link

ffmpeg exec command not running in nginx rtmp #963

Open evangeline123 opened 7 years ago

evangeline123 commented 7 years ago

I am using nginx and rtmp module to stream live hls and mpeg-dash. here is my rtmp command in nginx .conf

rtmp {
server {
    listen 1936;

    application mypull {
    live on ;
    meta copy;
    allow play all;

    pull rtmp://184.72.239.149/vod/BigBuckBunny_115k.mov name=test live=1;

    exec_push   /usr/bin/ffmpeg -re -i rtmp://localhost:1936/mypull/$name -vcodec libx264 -acodec libmp3lame -f flv rtmp://localhost:1936/hls/$name;

}

application dash {
        live on;
        dash on;
        dash_path /tmp/dash;
        dash_nested on;
        dash_fragment 5s;
        dash_playlist_length 30s;
    }
     application hls {
        live on;
        hls on;
    hls_playlist_length 30s;
    hls_fragment 5s;
        hls_path /tmp/hls;
    }
}
}

but it is not playing. it seems that the ffmpeg command is not even running. and the hls and dash folders are empty. could anyone help me with it?

jadsonlourenco commented 7 years ago

I have the same question, thanks!

zorrigas commented 7 years ago

Use a SH file.

Config: exec /opt/hls.sh $name;

Example SH File: ffmpeg -i rtmp://localhost/live/$1 -async 1 -vsync -1 -c:v libx264 -c:a ...

Works for me!

aamelegy commented 7 years ago

it could be nginx trying to run the command but fails for some reason, may be a missing codec for example. try running your command without nginx and see if it is working without errors

begetan commented 7 years ago

I am using directive exec_static in this case.

Just replace exec_push with above one. It will start streamig immediatelly aftere start nginx process.

sassyn commented 7 years ago

Did u manage to solve it?

Nothing works for me in terms of exec command;

server { listen 1935; ping 3m; ping_timeout 30s; notify_method get;

  application myapp {
     live on;
     exec_options on;

 exec_push /usr/bin/ffmpeg -i rtmp://localhost/src/$name -vcodec libx264 .... rtmp://localhost/hls/$name 2>>/var/log/ffmpeg-$name.log;
   exec_push /usr/bin/ffmpeg -version  > /tmp/xxxx;
   exec_pull /usr/bin/ffmpeg -version  > /tmp/xxxxsss;
   exec_static  /usr/bin/ffmpeg -version  > /tmp/xxxxsss;
   exec /usr/bin/ffmpeg -version  $name  >> /tmp/xxxxsss;
}

}

Nothing seems to work. I even run the nginx as root user.

I'm also compile with --debug

here is the nginx -v output:

nginx version: nginx/1.10.0 (Ubuntu) built with OpenSSL 1.0.2g 1 Mar 2016 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --with-file-aio --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/headers-more-nginx-module --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-auth-pam --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-cache-purge --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-dav-ext-module --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-development-kit --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-echo --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/ngx-fancyindex --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-http-push --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-lua --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-upload-progress --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/nginx-upstream-fair --add-module=/opt/src/nginx-server/nginx-1.10.0/debian/modules/ngx_http_substitutions_filter_module --add-module=/opt/src/nginx-rtmp-module/

Any idea? I'm running Ubuntu 16.04. Disable the apparmor. Nothing in the logs, or in dmesg/syslog.

zorrigas commented 7 years ago

Again, use a sh file, and parse name as argument.

exec /opt/hls.sh $name;

sassyn commented 7 years ago

It seems that the issue is with the NGINX version.

See here: https://github.com/arut/nginx-rtmp-module/issues/886

begetan commented 7 years ago

Here is working config for custom build version 1.11.10 and 1.10.1 on ubuntu:

rtmp {
    server {
        listen 1935; # Listen on standard RTMP port
        chunk_size 5000;
        allow play all;

        application src {
            live on;
            sync 50ms;
            exec_static /usr/bin/ffmpeg -i http://192.168.7.4:5112 -c:v libx264 -acodec aac -ac 1 -strict -2 -b:v 1024k -preset veryfast -deinterlace -f flv rtmp://1.2.3.4:1935/live/1tvrus 2>>/var/log/nginx/ffmpeg-1tvrus.log;

            allow publish 127.0.0.1;
            allow publish 1.2.3.4;
            deny publish all;
            deny play all;
        }
sassyn commented 7 years ago

Still not working.

I download version 1.11.9 recompile in ubuntu 16.04, rtmp working good! but exec command not running! :-(

nginx version: nginx/1.11.9 built with OpenSSL 1.0.2g 1 Mar 2016 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_secure_link_module --with-http_sub_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/headers-more-nginx-module --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nginx-auth-pam --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nginx-cache-purge --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nginx-dav-ext-module --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nginx-development-kit --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nginx-echo --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/ngx-fancyindex --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nchan --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nginx-lua --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nginx-upload-progress --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/nginx-upstream-fair --add-dynamic-module=/opt/src/nginx-server.dev/nginx-1.11.9/debian/modules/ngx_http_substitutions_filter_module --add-module=/opt/src/nginx-rtmp-module

What I'm doing wrong?

Thank You!

vmintam commented 7 years ago

Hi all,

same with openresty 1.11.2.4 and rtmp module. compiled everything is fine, but not working when use exec_pull or exec_push .

nginx version :

nginx version: openresty/1.11.2.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.8 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.18 --add-module=../redis2-nginx-module-0.14 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --add-module=/usr/local/src/ngx_cache_purge --with-pcre=/usr/local/src/pcre-8.40 --with-http_stub_status_module --with-http_slice_module --with-http_ssl_module --add-module=/usr/local/src/nginx-rtmp-module
winshining commented 7 years ago

They only works when you publish or play a stream on an application, for example: application myapp { live on; exec_push /usr/bin/ffmpeg -re -i rtmp://localhost/$app/$name -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost/hls/$name; }

application hls { live on; } When you publish a stream on myapp, then you can subscribe it on both myapp and hls. However, the stream on hls may be different from the stream on myapp, because it was transcoded.

vmintam commented 7 years ago

Hi winshining, this is my nginx rtmp config :

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
        application myapp {
                  live on;
                  exec_push /usr/bin/ffmpeg -i /tmp/test.sdp -ar 44100 -vcodec libx264 -acodec libmp3lame -f flv rtmp://127.0.0.1:1935/live/testing;
                  }

                  application live {
                  live on;
                  }
        }       
}

when i use VLC join to rtmp://127.0.0.1/live/testing ---> nothing happen. but when i use command : ffmpeg -i /tmp/test.sdp -ar 44100 -vcodec libx264 -acodec libmp3lame -f flv "rtmp://127.0.0.1/live/testing"

everything is fine.

any suggestion for me ?

thanks!

gustavogarciabr commented 7 years ago

Nice Job!

FingerRec commented 7 years ago

I solved this problem by adding below in first line of nginx.conf. user root It's Ridha Ben Njima's answer.

https://stackoverflow.com/questions/42388727/ffmpeg-exec-command-not-running-in-nginx-rtmp/45880931#45880931

winshining commented 7 years ago

@vmintam Try to push a stream to myapp, and then use vlc to join rtmp://127.0.0.1/live/testing. In fact, it's not suggested to use it as you set, the purpose of exec_push is to relay your push from one app to anohter:

rtmp {
    server {
        listen 1935;
        chunk_size 4096;
        application myapp {
            live on;
            exec_push /usr/bin/ffmpeg -re -i rtmp://127.0.0.1:1935/$app/$name -ar 44100 -vcodec libx264 -acodec libmp3lame -f flv rtmp://127.0.0.1:1935/live/testing;
        }

        application live {
            live on;
        }
    }
}

Then, you can push to myapp, play on live:)

neuronetv commented 6 years ago

I have the same problem - ffmpeg doesn't run when I start nginx. My question is: how would one find out what the error is? On my centos 6 server there's nothing in the console when I start nginx, I can't find an nginx log anywhere. I have a similar nginx.conf file as previous posts here and if ffmpeg won't start there must be a reason recorded somewhere. Thanks for any pointers.

zunair-syed commented 6 years ago

same here. trying to run the following: exec_static /usr/bin/ffmpeg -re -i rtmp://localhost:1935/hls/$name -c:a libfdk_aac -b:a 32k -c:v libx264 -b:v 128K -f flv rtmp://localhost:1935/hls/$name_low -c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 256k -f flv rtmp://localhost:1935/hls/$name_mid -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 512K -f flv rtmp://localhost:1935/hls/$name_hi -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 512K -f flv rtmp://localhost:1935/dash/$name_dash > /home/zsyed/Documents/logs.txt;

nswarnkar commented 6 years ago

I solved this problem by adding below in first line of nginx.conf. user root It's Ridha Ben Njima's answer.

https://stackoverflow.com/questions/42388727/ffmpeg-exec-command-not-running-in-nginx-rtmp/45880931#45880931

This is the issue, which I faced. Infact, redirecting the output of ffmpeg somewhere in /tmp can tell you the exact reasons. In my case, it was permission issue and it works fine. I am using as follow:

exec_push ffmpeg -i rtmp://localhost:1935/myapp/$name -c:v copy -c:a copy -segment_time 120 -f segment -reset_timestamps 1 -strftime 1 /opt/test_utils/$name_rtmp.mp4 2>>/tmp/ffmpeg.error;

xiafeiyue commented 3 years ago

I have the same question, thanks! The version I use is ngixn-1.18.0 I run the exec command in rtmp and it still doesn't work。

xiafeiyue commented 3 years ago

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39) configuration: --enable-static --enable-libx264 --enable-gpl --extra-libs=-ldl --enable-ffplay --prefix=/usr/local/ffmpeg-4.2.2 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 This is my ffmpeg version information

xiafeiyue commented 3 years ago

@zorrigas I tried the method you said, but it still doesn't work

xiafeiyue commented 3 years ago

@nswarnkar Did you solve the same problem?

nswarnkar commented 3 years ago

As mentioned above, I had changed the configuration and had permission issue( running under docker container). For me it had worked long back and using into production since then.

xiafeiyue commented 3 years ago

As mentioned above, I had changed the configuration and had permission issue( running under docker container). For me it had worked long back and using into production since then.

image exec /root/bin/ffmpeg -re -i rtmp://ip:1936/myapp/test -threads 2 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://ip:1936/hls/test1;

I tried the permission method you mentioned, but the ffmpeg command is still not executed,

xiafeiyue commented 3 years ago

@evangeline123 Did you solve the same problem? How did you solve this problem?

xiafeiyue commented 3 years ago

@ubone linux environment: My ffmpeg path is /usr/local/ffmpeg-4.2.2 My nginx path is /usr/local/nginx-1.18.0 I tried the above method but still did not execute the ffmpeg command。 exec_push /usr/local/ffmpeg -nostdin -loglevel 8 -re -i rtmp://ip:1936/myapp/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -s 480x360 -b:v 400k -bufsize 400k -threads 0 -r 30 -f flv rtmp://ip:1936/myapp/test; Why is this? Is the ffmpeg version of the problem?

jeffbski-rga commented 3 years ago

I found that I just needed to include the full path to ffmpeg and that fixed my problem. You can find the path using which ffmpeg

Using the latest nginx/1.19.6 and latest nginx-rtmp

I used this in my nginx.conf

exec /usr/local/bin/ffmpeg ...

chaijunkun commented 3 years ago

as @jeffbski-rga said, all exe command (exec_static, exec_pull, exec_push etc..) should include full path of programe. although your application has been placed to PATH env. 正如 jeffbski-rga 所述,所有的执行命令(exec_static, exec_pull, exec_push等等)都应当包含程序的完整路径。就算是这个程序的路径已经配置在了PATH环境变量,也不能省。

ngquocnhat9317 commented 1 year ago

Using file .sh and add exec_push /usr/bin/bash <filename>.sh $name; If still fail. check status nginx with systemctl status nginx If get error like that www-data : user NOT in sudoers ; TTY=unknown ; PWD=/ ; USER=root ...

Run that command line sudo usermod -a -G ubuntu www-data to add www-data permission into root user group