title: How to Stream With FFmpeg and NGINX RTMP
body: <p>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. </p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>If someone could shed some light of where I might be going wrong please that would be greatly appreciated.</p>
  
  <p><strong>nginx.conf</strong></p>
  
  <pre><code>#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;
          }
      }
  }
  </code></pre>
  
  <p>Many thanks</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Here's the path I'm trying to take:-</p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>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.</p>
  
  <p>Another question I have is, can the FFmpeg parameters be put on separate lines or do they have to all in one line?</p>
  
  <p>This is a really good site I have been referring back to</p>
  
  <p><a href="https://blog.twitch.tv/en/2017/10/10/live-video-transmuxing-transcoding-f-fmpeg-vs-twitch-transcoder-part-i-489c1c125f28/" rel="nofollow noreferrer">https://blog.twitch.tv/en/2017/10/10/live-video-transmuxing-transcoding-f-fmpeg-vs-twitch-transcoder-part-i-489c1c125f28/</a></p>