Debian 12 Linux Radio stream (rtmp) (Opam, gd, ffmpeg, Liquidsoap)
In this guide, we will create our own Internet radio and start broadcasting it on Youtube or Rutube (RTMP), add background animation and prepare a playlist. In this guide, we are installing as root, if you have a normal one, use the sudo command.
You can order a ready-made server with this configuration on the VPS server order form. |
Most frequently asked questions:
-
We want all the data to be with us. Can you make all this adjustment on our equipment?
Yes, you can order the installation and configuration of this configuration on your equipment using the link.
A fragment of the result of this configuration:
1. Install the necessary packages:
apt update
apt upgrade
apt-get install libfreetype6-dev
apt-get install opam
opam init
eval $(opam env)
opam switch create cs3110-2022fa ocaml-base-compiler.4.14.0
eval $(opam env)
opam depext gd ffmpeg liquidsoap
opam install gd ffmpeg liquidsoap
eval $(opam env)
2. Create folders for music, background video:
mkdir /home/radio
mkdir /home/radio/music
3. Let's create a configuration file for the radio station itself:
nano /home/radio/radio1.liq
# permission to run the script from the root user
settings.init.allow_root.set(true)
# metadata functions
song_author = ref('')
def apply_song(m) =
song_author := m["artist"]
end
song_title = ref('')
def apply_song2(m) =
song_title := m["title"]
end
def get_track_name_text()
"$(artist) - $(title)" % [
("artist", song_author()),
("title", song_title())
]
end
# audio source
audio = playlist(reload_mode="watch", "/home/")
audio = mksafe(audio)
# video source (gif, mp4)
background = single("/home/radio/")
# add logo
background = video.add_image(x=1120, y=20, width=153, height=56, file="/home/radio/", background)
# calling metadata
audio.on_track(apply_song)
audio.on_track(apply_song2)
# drawtext
background = video.add_text(color=0xFFFFFF, font="/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", speed=0, x=50, y=50, size=26,
get_track_name_text,
background)
# mixing sources
radio = mux_video(video=background, audio)
#rtmp+codec
url = "rtmp://"
enc = %ffmpeg(format="flv",
%video(codec="libx264", width=1280, height=720, pixel_format="yuv420p",
b="750k", maxrate="750k", minrate="750k", bufsize="1500k", profile="Main", preset="veryfast", framerate=30, g=60),
%audio(codec="aac", samplerate=44100, b="128k"))
# output
output.url(fallible=true, url=url, enc, radio)
3.1 Specify the URL variable depending on the service where you will be broadcasting:
Youtube
url = "rtmp://a.rtmp.youtube.com/live2/"
Rutube
url = "rtmp://rtmp-1.brz.rutube.ru/live_push/"
VK
url = "rtmp://ovsu.mycdn.me/input/"
3.2 Check in the configuration file that the path is correct as the music folder and place your music files there, the reload_mode="watch" option says that as soon as a new file appears in the folder, it will be immediately added to the playback queue.
audio = playlist(reload_mode="watch", "/home/")
3.3 Specify the correct path for broadcasting video background:
background = single("/home/radio/")
It can be a static png, jpg picture or video animation gif, mp4. The background animation file is looped.
3.4 Specify the correct path for your channel's logo file:
background = video.add_image(x=1120, y=20, width=153, height=56, file="/home/radio/", background)
Edit the size and position as needed.
4. Starting the radio and checking operation:
cd /home/radio
liquidsoap radio1.liq
The processing log will appear and if there are no errors, the translation is successful, go to the page where you created it and check the work.
4.1 Creating and auto-starting a service:
cd /home
apt install git
git clone https://github.com/savonet/liquidsoap-daemon.git
cd /home/liquidsoap-daemon
./daemonize-liquidsoap.sh /home/radio/radio1.liq
4.2 Commands:
Start
systemctl start radio1-liquidsoap
Stop
systemctl stop radio1-liquidsoap
Status
systemctl status radio1-liquidsoap
Our radio is ready, you can see what happened in the video example before starting the setup. This protocol is supported by a large number of popular services.