Skip to content

FoxxMD/rtl-sdr-icecast-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RTL-SDR (FM/HD) Radio Streaming to Icecast

This repository provides a docker-compose stack and all of the configuration necessary to use a RTL-SDR usb dongle to tune into a FM HD radio -- or any analogue signal supported by ShinySDR (AM, FM, SSB, CW) -- and generate a streaming endpoint that can be consumed by a media player.

Additionally, a yt-dlp container can be enabled to use a cron schedule for saving streams from the icecast endpoint.

How It Works

Accessing RTL-SDR device

Your host machine passes the RTL-SDR device to an rtl_tcp server (dockerized example) which is accessible over TCP for tuning and getting signal.

Tuner uses Signal

One of the available tuners, nrsc5 for HD FM or ShinySDR for general use, accesses the rtl_tcp server and tunes/converts the analogue signal into uncompressed, digital audio.

NOTE: Only one tuner can be used at a time!

Convert and stream to Icecast

ffmpeg is used to convert uncompressed audio into an mp3/ogg stream which is then streamed to icecast at the URL of your choosing. The URL can then be directly accessed by multiple clients to get streaming audio.

(Optional) Scheduled download of stream

yt-dlp is used alongside cron enabling you to schedule saving the stream at preset times and for an arbitrary duration.

Configuration

Make a copy of .env.example and rename to .env. This file should be located next to docker-compose.yml.

The below configuration details required and notable settings only. Review the comments in .env for more configuration.

Getting RTL-SDR USB Path

Determine the correct USB path to pass to the rtl_tcp service in order for it to access your radio device.

Run lsusb on the host machine with the rtl-sdr usb device plugged in to get a list of USB devices attached to your host. It will look like this:

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0032 Intel Corp. AX210 Bluetooth
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
...
Bus 005 Device 006: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Look for your device, it usually has RTL or DVB-T in the name. Use the Bus and Device identifiers to build the path to your usb device. EX:

Bus 005 Device 006: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T

/dev/bus/usb/005/006

Use this value in .env for USB_DEVICE

USB_DEVICE=/dev/bus/usb/005/006

Choosing a Tuner

YOU CAN ONLY USE ONE TUNER AT A TIME.

Use the provided docker compose profiles shown in usage to determine which to use.

nrsc5 (HD Radio)

nrsc5 is used to convert digital (HD) FM radio to a usable audio signal. This audio will have (almost) zero static and be a higher quality than the analogue audio signal for normal FM radio.

Use the numeric value for the analog radio station that has the HD Radio you want to tune to.

Example WABE 90.1 FM => 90.1

Use this value in .env for RADIO_STATION

RADIO_STATION=90.1

ShinySDR

ShinySDR is a general purpose radio receiver with a web-based interface. It can play most analogue signals and decode many common digital signals. It cannot decode HD radio at this time.

The audio sent to Icecast will be whatever you have tuned ShinySDR to using its web interface.

Icecast

Optionally, set the name of the icecast station that will broadcast your signal. The default is myradio.

Uncomment and set station name in .env for ICECAST_STATION_NAME

ICECAST_STATION_NAME=myradio

The stream will be available at http://localhost:8000/myradio (or whatever you set)

(Optional) Scheduled stream downloads

Schedule an optional yt-dlp container to save audio streams to mp3:

  • Make a copy of /config/ytdl/crontabs/abc.example and rename to abc (no extension)
  • Edit /config/ytdl/crontabs/abc:
    • set the cron expression for when the stream should start recording
    • edit downloading length --download-sections "*0-20" in seconds IE *0-20 = save the first 20 seconds of the stream

Note: If you run Docker on a Linux Host see the instructions in your .env under ### YTDL ### for PUID/PGID to set file permissions correctly.

Example Usage

The tuner that is used, along with whether optional stream downloads are enabled, are configured using docker compose profiles. These profiles are set in the .env under COMPOSE_PROFILES.

Use ONE OF:

  • hd => nrsc5 hd radio tuner
  • fm => shiny for fm radio

and optionally ytdl to enable ripping icecast streams.

Multiple profiles are separated by a comma.

Examples:

  • COMPOSE_PROFILES=hd,ytdl => hd radio + icecast + ytdl scheduled downloads
  • COMPOSE_PROFILES=fm,ytdl => shiny + icecast + ytdl scheduled downloads
  • COMPOSE_PROFILES=hd => hd radio + icecast
  • COMPOSE_PROFILES=fm => shiny + icecast

After setting this start the stack

docker compose up

Your icecast broadcast will now be available at http://localhost:8000/myradio (or whatever you set) and, if enabled, stream saving is now enabled.