Code Monkey home page Code Monkey logo

rtl-sdr-icecast-docker's Introduction

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.

rtl-sdr-icecast-docker's People

Contributors

foxxmd avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

damienclaveau

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.