Code Monkey home page Code Monkey logo

nginx-obs-automatic-low-bitrate-switching's Introduction

    ███╗   ██╗ ██████╗  █████╗ ██╗     ██████╗ ███████╗
    ████╗  ██║██╔═══██╗██╔══██╗██║     ██╔══██╗██╔════╝
    ██╔██╗ ██║██║   ██║███████║██║     ██████╔╝███████╗
    ██║╚██╗██║██║   ██║██╔══██║██║     ██╔══██╗╚════██║
    ██║ ╚████║╚██████╔╝██║  ██║███████╗██████╔╝███████║
    ╚═╝  ╚═══╝ ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝ ╚══════╝

nginx-obs-automatic-low-bitrate-switching

How to video:

YouTube: How to Download, Install and Run NOALBS for IRL Livestreaming


Simple app to automatically switch scenes in OBS based on the current bitrate fetched from an RTMP server's stats page.

Don't feel like setting this all up by yourself? Check out these links for similar solutions!

Build Prerequisities

This script uses OBS plugin "obs-websocket" in conjunction with "OBS-Studio". For monitoring "NGINX-RTMP" (see links below).

It supports monitoring streams on either NGINX-RTMP server or Node-Media-Server. Node-Media-Server is also built into NOALBS for an easy all-in-one streaming solution.

Installation from Source

  • git clone <repository-url> or download from RELEASES
  • Change into the new directory.
  • npm install --production

If you already have NGINX-RTMP server

  • Replace your nginx.conf with the one given here.
  • Put stat.xsl in your nginx folder.

Otherwise here is a Windows version of NGINX+RTMP Server

  • Hosted on Github
  • Everything is ready to go inside this zip, just extract and click on the nginx_start.bat file to start NGINX, you can use nginx_stop.bat to stop NGINX. HTTP server runs on Port 80, RTMP server runs on 1935, if you need to edit the config file it's in the /conf folder, named nginx.conf.

Config

Edit config.json to your own settings.

Here is an example config with comments (click to enlarge):

PLEASE NOTE CONFIG MAY NOT REPRESENT CURRENT CONFIG

alt text

  • Use https://twitchapps.com/tmi to get your oauth from Twitch for use with chat commands.

    We recommend using your main Twitch BOT account for this, but if you do not have a Twitch Bot account just use your Main Twitch Account.

Also if you are going to be using your Twitch BOT Account please make sure it is an 'Editor' of your channel, see example;

Go to this URL: Twitch User Roles, Find your bot on the list, add checkmark to 'Editor', done.

alt text

How to run from source

Run the node app by running: npm start. Then stream to rtmp://IPHERE/publish/live

Chat Commands

This script gives you the option to enable some simple chat commands to help you manage your stream from your own Twitch chat, here is how to use them:

Please note: Admins are all the users in the "adminUsers" array in the config, MODs (if enabled in the config) are all of your MODs, and Public (if enabled in the config) is anyone in your chat.

Default Role Command Description Example
Admins !host (channelname) hosts said channel, and stops streaming in OBS if enabled in config. !host 715209
Admins !unhost unhosts whoever you are currently hosting. !unhost
Admins !raid (channelname) raids said channel and stops streaming in OBS if enabled in config. !raid 715209
Admins !start on-demand command to start streaming in OBS. !start
Admins !stop on-demand command to stop streaming in OBS. !stop
Admins !rec (on/off) on-demand command to start/stop recording in OBS. !rec on
Admins !switch (scene) switches to the provided SCENE (fuzzy match). !switch INTRO
Admins !alias (add/remove) (alias) (command) add an alias for a command !alias add ss switch
MODs !refresh changes to the REFRESH scene for the set interval. !refresh
MODs !fix tries to fix the stream. !fix
MODs !trigger (value) changes the low bitrate threshold to the defined value. !trigger 1000
MODs !sourceinfo gives you details about the SOURCE in chat. !sourceinfo
MODs !obsinfo gives you details about OBS in chat. !obsinfo
Public !bitrate returns current BITRATE !bitrate

You can also enable/disable certain features from chat, see below:

Default Role Command Description Example
Admins !public (on/off) enables/disables the use of Public commands. !public off
Admins !mod (on/off) enables/disables the use of MOD commands. !mod on
Admins !notify (on/off) enables/disables the notifications in chat. !notify off
Admins !autostop (on/off) enables/disables the auto stop feature when you host/raid. !autostop on

Running with Node-Media-Server

Using the inbuilt server

Defining a nodeMediaServer block in config.json will enable a fully functional node-media-server RTMP server to accept incoming streams:

    "rtmp": {
        "application": "publish",
        "key": "live"
    },
    "nodeMediaServer": {
        "rtmp": {
            "port": 1935,
            "chunk_size": 60000,
            "gop_cache": true,
            "ping": 30,
            "ping_timeout": 60
        },
        "http": {
            "port": 8000
        }
    },

The nodeMediaServer object is passed directly as the node-media-server configuration, more details here. It will also automatically fill out the rtmp server type and stats fields.

Note: This is probably best for local connections and testing only unless you enable authentication

Using an external server

Modify the RTMP section in config.json like this to connect to a node-media-server running externally:

    "rtmp": {
        "server": "node-media-server",
        "stats": "http://localhost:8000/api/streams",
        "application": "publish",
        "key": "live"
    },

Using nimble SRT instead of nginx rtmp

Nimble must have API access enabled and be configured as a SRT receiver - see "Set up receiving of SRT" and have an outgoing stream ("Add outgoing stream" on same page)

Modify the RTMP section in config.json to this:

    "rtmp": {
        "server": "nimble",
        "stats": "http://nimble:8082",
        "id": "0.0.0.0:1234",
        "application": "live",
        "key": "srt"
    },
  • stats: URL to nimble API
  • id: UDP listener ID (Usually IP:Port)
  • application: Outgoing stream "Application Name"
  • key: Outgoing stream "Stream Name"

Switches on low bitrate or high RTT (high RTT seems to be a more accurate way of determining if the stream is bad with this)

You can change the high RTT trigger value inside config.json:

    "obs": {
        ...
        "highRttTrigger": 2500,
    },

Help it won't change scenes

It will only change scenes when OBS is set on a scene that's in the config.
(This is so that it wont change when you are on for example your 'intro' or 'locked-brb' scene)

nginx-obs-automatic-low-bitrate-switching's People

Contributors

715209 avatar adraenyse avatar b3ck avatar dependabot[bot] avatar jhn-k avatar ladelltwitch avatar novex avatar otivedani avatar romanovdaily avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.