简体   繁体   中英

How to Stream With FFmpeg and NGINX RTMP

I'm trying to stream from OBS (open broadcast software) on my Windows PC to NGINX+RTMP also installed on the same PC. I have set a bitrate of 20,000Kbps in OBS which will be the foundation bitrate for the multiple streams I aim to setup within NGINX.

I would like to be able to stream into NGINX and then on-the-fly use FFmpeg to transcode the stream to comply with the streaming site I intend to broadcast to, for example Twitch.tv.

I can view my stream via VLC if I use the network path rtmp://localhost/live/test. However, when I'm on Twitch's inspector site to see if my stream is coming thorugh, I'm not receiving anything. I have no idea if my FFmpeg is working or there is something wrong with my NGINX configuration below.

If someone could shed some light of where I might be going wrong please that would be greatly appreciated.

nginx.conf

#user www-data;
worker_processes  1;

events {
    worker_connections  1024;
}

http { 
    server_tokens off;

    include mime.types;
    default_type application/octet-stream;
    sendfile off;
    keepalive_timeout 65;

    server {
        listen 80;
        server_name localhost;

        # make a internal server page and put it in html
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }
}

rtmp {
    server {
        listen 1935;
        chunk_size 8192;

        application live {
            live on;
            #interleave on;
            #wait_video on;
            record off;

            # Twitch
            exec_push "D:\Users\Will\Downloads\ffmpeg\bin"
                -i rtmp://localhost/source/$name 
                -c:v libx264 
                -c:a copy 
                -preset veryfast 
                -profile:v high 
                -level 4.1
                -x264-params "nal-hrd=cbr" "opencl=true"
                -b:v 8000K 
                -minrate 8000K 
                -maxrate 8000K
                -keyint 2
                -s 1920x1080
                push rtmp://live-lhr03.twitch.tv/app/STREAM_KEY;
        }
    }
}

Many thanks

UPDATE 1

For the sake of simplicity I'm testing OBS, NGINX and FFmpeg all on the same physical computer, a Windows PC. Once everything is working I will port NGINX and FFmpeg to my Linux PC.

I'm using a pre-compiled version of NGINX with the RTMP module baked in. I've also downloaded the latest FFmpeg libraries which I have set a path environment variable for in Windows so that FFmpeg commands can be called in CommandPrompt/PowerShell.

Here's the path I'm trying to take:-

OBS is encoding x264 at 20,000Kbps and it's destination is a RTMP application in NGINX called 'live'. From here I want to encode the one stream derived from OBS into several smaller bandwidth streams so that I can comply with streaming service's requirements such as Twitch and Mixer for example.

At the end of the FFmpeg parameters do I push the output directly to Twitch or take the output of FFmpeg and send back into a second RTMP application on NGINX and then push out to Twitch?

One advantage of pushing FFmpeg's output back into NGINX before going off to the external stream service is I can open the FFmpeg transcoded stream through a RTMP supported player such as VLC for example, allowing me to view the compressed output.

Another question I have is, can the FFmpeg parameters be put on separate lines or do they have to all in one line?

This is a really good site I have been referring back to

https://blog.twitch.tv/en/2017/10/10/live-video-transmuxing-transcoding-f-fmpeg-vs-twitch-transcoder-part-i-489c1c125f28/

Your ffmpeg command is trying to connect to rtmp://localhost/source But you namd the application “live”, not “source”

Also, don't sent the level manually unless you truly understand how levels work, and what there constraints are. X264 will also pick the best level automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM