Making Game: ffmpeg inside nginx-rtmp module doesn’t work when scaling video

Original Source Link

So I setup an nginx RTMP server using this rtmp module. Below is my nginx.conf that I made following this guide.

rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record off;

                application movie {
                        live on;
                        record off;

                        exec ffmpeg -i rtmp://localhost:1935/movie -async 1 -vsync -1
                                -c:v libx264 -c:a libvo_aacenc -b:v 256k -b:a 32k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:1935/hls/movie_low
                                -c:v libx264 -c:a libvo_aacenc -b:v 768k -b:a 96k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:1935/hls/movie_mid
                                -c:v libx264 -c:a libvo_aacenc -b:v 1024k -b:a 128k -vf "scale=960:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:1935/hls/movie_high
                                -c:v libx264 -c:a libvo_aacenc -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost:1935/hls/movie_hd720
                                -c copy -f flv rtmp://localhost:1935/hls/movie_src;

                application hls {
                        live on;
                        hls on;
                        hls_path /tmp/hls;
                        hls_nested on;

                        hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution
                        hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
                        hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution
                        hls_variant _hd720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
                        hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution

For some reason, scaling the video with -vf "scale=..." doesn’t work (same goes for using the -s wxh flag), as no output is created. I verify this by checking the stat page that the rtmp module provides. When I begin streaming to the server, the /movie application shows data streams, but the /hls application gets nothing. If I remove the -vf "scale=..." flags then everything works as expected with 5 streams under the /hls application. Am I doing something wrong? I would like to have scaling as I don’t want to be sending the same resolution across different bitrates. My version of nginx is 1.16.1, and this is all running on Ubuntu 18.04.

After running the ffmpeg command in the command line as per @BenXO’s suggestion, I got an error about libvo_aacenc not found, i.e. this snippet was the issue: -c:a libvo_aacenc. A quick search yielded that ffmpeg no longer supports this encoder and it’s recommended to just use aac. Changing all instances of -c:a libvo_aacenc to -c:a aac fixed the issue.

Tagged : / / /

Leave a Reply

Your email address will not be published. Required fields are marked *