Get 7 in 1 Digital Success Bundle Today!

Click HERE To Check Professional Indian Courses more then 45+ Courses
Canva Pro Lifetime Invite Link FREE
IIT JEE & NEET Preparation Material
All Famous Digital Marketing Course
★ Fresh Graphic Designing MEGA PACK 2021400+ Life Changing EbooksAccess to 60 Google Groups Collection ★
★ Unlimted Google Drive StorageUnlimited Guide To Social Media MarketingPremium & High Quality 2000+ Android APPS Source Code ★
Email me For Courses Links Click HERE
Telegram Ihtreek Tech
Telegram Ihtreek Tech
Telegram Ihtreek Tech
Big Billion Day Sale
Amazon SALE Live Flipkart The Big Billion Days SALE LIVE Offers On Electronics
Skip to content

How to create your 24/7 YouTube online radio Latest Method

How to create your 24/7 YouTube online radio Latest Method

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.

How to create your 24/7 YouTube online radio Latest Method

  1. Rent a 24/7 server with a stable internet
  2. Use Azuracast to create an audio stream
  3. Upload mp3/wav files (mind the license)
  4. 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.

1*iBkJV7wsRaSCvBWvQXQS g
My radio server configuration

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

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.
#! /bin/bash  VBR="1500k" FPS="24" QUAL="superfast"  YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2" KEY="z5k3-8888-69qu-9999"  VIDEO_SOURCE="/home/root/cover.gif" AUDIO_SOURCE="http://localhost/radio/8000/radio.mp3"  ffmpeg \     -re -f lavfi -i "movie=filename=$VIDEO_SOURCE:loop=0, setpts=N/(FRAME_RATE*TB)" \     -thread_queue_size 512 -i "$AUDIO_SOURCE" \     -map 0:v:0 -map 1:a:0 \     -map_metadata:g 1:g \     -vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR \     -acodec libmp3lame -ar 44100 -threads 6 -qscale:v 3 -b:a 320000 -bufsize 512k \     -f flv "$YOUTUBE_URL/$KEY"

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:

  1. using Azuracast API — you can periodically get the current radio track
  2. 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.

import os, json from flask import Flask, request  app = Flask(__name__)  FNAME = "song.txt"  @app.route('/', methods=['POST','GET']) def index():     with open(FNAME, "w") as f:         req_data = request.get_json()         if "now_playing" in req_data:             if "song" in req_data["now_playing"]:                 if "text" in req_data["now_playing"]["song"]:                     text = req_data["now_playing"]["song"]["text"]                     f.write(text)          return '{"success":"true"}'  if __name__ == "__main__":        app.run(host='0.0.0.0', port=5000)

This is the new FFmpeg launcher that writes text on a video stream:

#! /bin/bash  VBR="1500k" FPS="24" QUAL="superfast"  YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2" KEY="z5k3-8888-69qu-9999"  VIDEO_SOURCE="/home/root/cover.gif" AUDIO_SOURCE="http://134.122.81.86/radio/8000/radio.mp3" NP_SOURCE="/home/root/song.txt" FONT="/home/root/VinMonoPro-Light.ttf"  ffmpeg \     -re -f lavfi -i "movie=filename=$VIDEO_SOURCE:loop=0, setpts=N/(FRAME_RATE*TB)" \     -thread_queue_size 512 -i "$AUDIO_SOURCE" \     -map 0:v:0 -map 1:a:0 \     -map_metadata:g 1:g \     -vf drawtext="fontsize=20: fontfile=$FONT: \         box=0: [email protected]: boxborderw=20: \         textfile=$NP_SOURCE: reload=1: [email protected]: x=50: y=th" \     -vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR \     -acodec libmp3lame -ar 44100 -threads 6 -qscale:v 3 -b:a 320000 -bufsize 512k \     -f flv "$YOUTUBE_URL/$KEY"

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!

Leave a Reply

Your email address will not be published.

close