How to create your 24/7 YouTube online radio
How to create radio like lofi hip hop radio — beats to relax/study to or Russian underground radio by Post Market 1919? I’ve created a bunch of these and I’ll tell you how. Warning: a lot of geek stuff will be here.
TL;DR
- Rent a 24/7 server with a stable internet
- Use Azuracast to create an audio stream
- Upload mp3/wav files (mind the license)
- Use FFmpeg to create a video stream from .mp4 / .gif, merge it with an audio stream with ‘current track’ title and send it to YouTube
Need more details and a step-by-step guide? Let’s go!
1. Find a stable server
Of course, you can host your 24/7 radio on your Laptop or Raspberry pi, but if you have some strong planes on your radio or just don’t want a headache I’d strongly recommend ordering a 24/7 server with great Internet connections. Digitalocean is one of the greatest and cheapest solutions right now — use my referral to get $100 free to start and test your radio.
What about server configurations?
My current configuration is 4GB RAM / 2CPUs / 80 GB SSD / 4 TB transfer.
My average CPU load is 55%, outbound bandwidth: 1.58 Mbps.
It would probably be enough with a cheaper server but I don’t want to hit the limits — they cause a headache.
2. Install Azuracast
If you are using Digital Ocean as your VPS provider, there is a prepaid server configuration with Azuracast installed. So you can just install all Azuracast dependencies without any hassle in Terminal (but you will definitely have some soon while installing FFmpeg for merging audio and video streams and sending them to YouTube).
If you want to install Azuracast from scratch — use this official tutorial.
3. Setup Azuracast and Upload tracks
After successful installation, just visit Azuracast address to complete the setup. Then you just upload song files to the system, create playlists with them — and your radio is already can be listened via Azuracast’s public page (you can find its link in your admin panel).
4. Install FFmpeg
Now you need this great tool to create a video stream out of your animated .gif or .mp4 file, merge it with your audio stream from Azuracast and pass all of them to YouTube.
To install FFmpeg type this in your terminal:
sudo apt install ffmpeg
Or visit this official site: http://ffmpeg.org/download.html
5. Run FFmpeg
Now some magic will be happening: FFmpeg is so powerful it will merge our Azuracast’s audio stream and video stream from your .gif/.mp4 animated cover.
Check my production code below. Some descriptions to used variables:
- YOUTUBE_URL — the URL of YouTube’s streaming service.
- KEY — the unique key to control your stream. You can find yours straight after the creation of a new youtube online stream (Youtube will give it to you). Keep it safe!
- VIDEO_SOURCE — path to a file with your animated cover that is located on your server (you can use
scp
utility to transfer files to your machine). - AUDIO_SOURCE — URL to your audio stream. Replace the IP with your host.
You would probably need to wrap up this bash script (with FFmpeg) to systemd service. It will relaunch the script after it somehow fails (and it will sometimes).
6. Add CURRENT TRACK captions on a video
FFmpeg is so powerful it can add a text on the video stream. It can read text from a text file and write its text on the video using your font and coordinates.
You need to create a code that will write a current track name in a text file. There are two ways to do that:
- using Azuracast API — you can periodically get the current radio track
- using Azuracast Webhooks — you can receive data when song changes
I chose the second variant. You can find a Webhook section in Azurast admin panel. This is my production python code that handles the webhook and writes a song name to the file.
This is the new FFmpeg launcher that writes text on a video stream:
Notice that I also have to upload a font file to the server machine. You can also google for -vf drawtex
params to play with song name positioning.
I hope you enjoyed this article! If you create an online radio station using this tutorial — please share its link in the comments section. Please follow me for more hacks and do the clap-clap thing!
— — — — — — — — Daniil Okhlopkov / okhlopkov.com