Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/foxxmd/rtl-sdr-icecast-docker
Relay HD radio through icecast and save to mp3
https://github.com/foxxmd/rtl-sdr-icecast-docker
cron docker fm-radio hd-radio icecast mp3 rtl-sdr stream ytdl ytdlp
Last synced: 2 months ago
JSON representation
Relay HD radio through icecast and save to mp3
- Host: GitHub
- URL: https://github.com/foxxmd/rtl-sdr-icecast-docker
- Owner: FoxxMD
- Created: 2023-12-15T19:16:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-29T20:56:05.000Z (7 months ago)
- Last Synced: 2024-06-30T23:46:06.388Z (7 months ago)
- Topics: cron, docker, fm-radio, hd-radio, icecast, mp3, rtl-sdr, stream, ytdl, ytdlp
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://www.rtl-sdr.com/about-rtl-sdr/) to tune into a FM HD radio -- or any analogue signal supported by [ShinySDR](https://shinysdr.switchb.org/) (AM, FM, SSB, CW) -- and generate a streaming endpoint that can be consumed by a media player.
Additionally, a [yt-dlp](https://github.com/yt-dlp/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](https://manpages.ubuntu.com/manpages/lunar/en/man1/rtl_tcp.1.html) ([dockerized example](https://hub.docker.com/r/kosdk/rtl-tcp)) which is accessible over TCP for tuning and getting signal.
#### Tuner uses Signal
**One of the available tuners**, [nrsc5](https://github.com/FoxxMD/nrsc5-rtlsdr-icecast) for HD FM or [ShinySDR](https://github.com/jeffersonjhunt/shinysdr-docker) 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](https://github.com/jee-r/docker-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](https://github.com/yt-dlp/yt-dlp) is [used alongside cron](https://github.com/FoxxMD/ytdl-cron-docker) enabling you to schedule saving the stream at preset times and for an arbitrary duration.
# Configuration
**Make a copy of [`.env.example`](/.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](https://docs.docker.com/compose/profiles/) shown in [usage](#example-usage) to determine which to use.
### nrsc5 (HD Radio)
[nrsc5](https://github.com/theori-io/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](https://shinysdr.switchb.org/) 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](https://github.com/yt-dlp/yt-dlp) container to save audio streams to mp3:
* Make a copy of [/config/ytdl/crontabs/abc.example](/config/ytdl/crontabs/abc.example) and rename to `abc` (no extension)
* Edit /config/ytdl/crontabs/abc:
* set the [cron expression](https://crontab.guru/) 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 streamNote: 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](https://docs.docker.com/compose/profiles/). These profiles are set in the `.env` under `COMPOSE_PROFILES`.
Use ONE OF:
* `hd` => nrsc5 hd radio tuner
* `fm` => shiny for fm radioand 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 + icecastAfter setting this start the stack
```shell
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.