Page 1 of 1

Simulcasting with OBS and NGINX

Posted: Thu Nov 16, 2023 5:19 am
by MattKC
If Twitch's announcement that they're allowing simulcasting has gotten you interested in trying it, here's a way you can do it completely with FOSS!
  1. Install NGINX with the RTMP module. The RTMP module is required and doesn't come with normal builds of NGINX. Acquiring this will differ per platform:
    • For Windows, I haven't tested, but I believe these builds have RTMP support built in (at least Gryphon does): http://nginx-win.ecsds.eu/download/
    • For macOS, you can use brew to install the following:

      Code: Select all

      brew install nginx-full --with-rtmp-module --with-debug
      
    • For Ubuntu Linux, you can use apt to install the following:

      Code: Select all

      apt install nginx libnginx-mod-rtmp
      
    • For Arch Linux, the RTMP module is only available in the AUR. If you're using yay, you can do the following:

      Code: Select all

      yay -S nginx nginx-mod-rtmp
      
  2. Configure your RTMP server by adding the following lines to the end of your "nginx.conf" file:

    Code: Select all

    rtmp {
      server {
        listen 1935;
        chunk_size 4096;
        allow publish 127.0.0.1;
        deny publish all;
     
        application live {
          live on;
          record off;
          push rtmp://live.twitch.tv/app/<TWITCH_STREAM_KEY>;
          push rtmp://a.rtmp.youtube.com/live2/<YOUTUBE_STREAM_KEY>;
        }
      }
    }
    
    This opens an RTMP server on port 1935. It also prevents any computer from streaming to it except the computer it's running on (a basic security measure). Then it creates an "application" called "live" that accepts transmissions and then "pushes" it to, in the example, Twitch and YouTube. If you're using this example directly, make sure to change <TWITCH_STREAM_KEY> and <YOUTUBE_STREAM_KEY> to your actual stream keys.

    Every push you add is an additional output. Adding/removing streaming services is as simple as adding/removing pushes. As long as your upload speed can handle it, you can add as many streaming services as you'd like. Most streaming services will have their RTMP information listed somewhere, for other services you'll have to find it yourself.
  3. Try starting NGINX! Assuming everything is configured correctly, you should be able to run NGINX and it shouldn't throw an error. If it does throw an error, check over the configuration and make sure it matches the configuration above.
  4. Set OBS to transmit to your local RTMP server. This is fairly straight forward, just open Settings > Stream, and set the "Service" to "Custom". Then, set the server to the following:

    Code: Select all

    rtmp://127.0.0.1:1935/live
    
    You can see the configuration we set above being used here: we stream to port 1935 and application "live". It's possible to change the port or add other applications for other purposes and then stream to those if you'd like.
That's it! If everything worked out, you now have a full simulcasting/multistreaming set up on your PC!