I-330 - Posts

Posted: January 28, 2023 by I-330

Agora Radio. Why it "doesnt" suck

Preface :

Are you a nerd that listens to music all day? Do you want to force your music tastes onto other people? Well than this is the post for you. Over the past couple months, in collaboration with agora road's only @h00, we created a radio station with the sole purpose of converting vaporwave fans into Drum & Bass appreciators.

So how does it work? Well, like all good things in life, it begins with an insecure rtmp stream running from a terrible internet connection thousands of miles from its public relay. The stream itself has been online since mid 2022, but has only been actively broadcasting since late 2022. If you want to check it out, you can give it a listen here.

RTMP :

The initial rtmp stream originates from an old Dell PC which renders the visualizer, plays the audio, and send the broadcast via OBS to a bounce server hidden somewhere in the Central United States. Once it hits the bounce server, the stream is re-broadcast publicly with significantly more bandwidth and security, where it can be listened in on by anyone with an rtmp compatible media player (vlc, mpv, kodi).

However, because you can't tune-in to an rtmp stream through a web browser, some adjustments had to be made to the stream. Using ffmpeg, we were able to convert the rtmp stream into two seperate audio & audio/video streams. These streams are then passed through an application called icecast2 which creates a web-based video & audio stream which can be embeded into any webpage.

The ffmpeg script:

while true;
do ffmpeg -i rtmp://162.142.45.168:420/agora/radio \
-acodec libopus -b:a 64k \
-vcodec libvpx -b:v 500K -crf 25 -vf scale=720:480 -content_type video/webm \
icecast://source:PASSWD@LOCALIP:PORT/livevid.webm;
sleep 10;
done

ICECAST2 & WEB :

The Icecast2 stream isn't perfect though, and it must be encrypted in order for modern web browsers to support it. To do this, I created a cloudflare tunnel from my server and forwarded its traffic to a pre-configured domain address. This provided both a way to ensure SSL encryption, as well as providing a globally available control panel that I can use to adjust icecast2 settings on the fly.

From here, the rest was relatively easy. I designed a simple web interface for people to listen in on, and embeded the Icecast2 audio stream. The WinAmp player on the site was imported from a project called Webamp, which re-implemented Webamp2 in Javascript with live audio playback and Milkdrop support. I am still working on a way to embed the video stream without destroying my bandwidth or killing the video quality. However, I do plan on having an alternative to the rtmp video live on the site soon... maybe.