$ cat rtmp_radio


Making a simple RTMP radio station

I really like listening to music while I study, but sometimes deciding what to listen to can turn into its own procrastination session of listening to different albums, so stations like 24/7 lofi are nice to just tune into. There's a problem with that though, I don't like lofi. I like listening to music with a little faster pace (mostly DnB). So I ended up making my own radio station with Nginx, OBS, and Mullvad on a Debian host.

Setting up Mullvad

Because I only have a residential network and don't want to have a recurring charge for a VPS that only does one thing, I'll be making use of Mullvads port-forward feature for VPN sessions. Setup of this is quite simple, pull the latest binary from Mullvads site and install it withsudo apt install ./MullvadVPN* after starting the app and getting connected via wireguard, take note of your Device Name and navigate to Manage Devices and Ports. Here select your devices exit location and Device Name associated WireGuard key and "Add Port", this will open a random internet accessible port that we'll face our RTMP stream to. We'll refer to this port as $mlvd_port

Setting up Nginx

RTMP support isn't supported in Nginx by default, so we'll need to compile it manually with the feature added. Runsudo apt install build-essential libpcre3-dev libssl-dev libpcre3 then download the latest Nginx build and also the latest RTMP module. Once downloaded,

tar xzvf nginx-rtmp*gz && rm nginx-rtmp*gz
mkdir nginx && tar xzvf nginx*gz -C nginx && rm nginx*gz
cd nginx/*
./configure --with-http_ssl_module --add-module=../../nginx-rtmp*
make && sudo make install

Now nginx is installed, but before we start it make sure your /usr/local/nginx/conf/nginx.conf contains the following at the end of the file.

rtmp {
  server {
    listen $mlvd_port;
    chunk_size 4096
    application live {
      live on;
      record off;
    }
  }
}

Then start it withsudo /usr/local/nginx/sbin/nginx

Setting up OBS

Simply install OBS withsudo apt install obs-studio, launch it, and during the quickstart select "Custom" as the service you're streaming to, with Server as "rtmp://127.0.0.1:$mlvd_port/live" and Stream Key as "music", set up your scene and start streaming!

Listening

Now that we're all set up it's time to tune in, to find the public ip that we're broadcasting to usecurl https://am.i.mullvad.net/connected, and then tune in withmpv $ip:$mlvd_port/live/music, any other rtmp client will work just as well (such as VLC).
Now just enjoy the music!