Skip to content
Stream an audio cd to a chromecast
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Stream an audio cd to a chromecast

We will use an icecast server, to install it:

$ sudo apt-get install icecast2

Icecast2 server will broadcast the audio feed

And we need ffmpeg, which will stream audio cd to icecast2 feed:

$ sudo apt-get install ffmpeg

Some configuration, for icecast2: edit the /etc/icecast2/icecast.xml file, and check the authentication part:

        <!-- Sources log in with username 'source' -->
        <!-- Relays log in with username 'relay' -->

        <!-- Admin logs in with the username given below -->

And the hostname and socket part:


<!-- You may have multiple <listener> elements -->
    <!-- <bind-address></bind-address> -->
    <!-- <shoutcast-mount>/stream</shoutcast-mount> -->

You can see the full config file in the Chromecast-audio-cd-caster repo

To stream using ffmpeg, simply use:

/usr/bin/ffmpeg  -f libcdio -ss 0 -i /dev/cdrom -acodec libmp3lame -ab 48k -bufsize 15 -ac 1 -content_type audio/mpeg -f mp3  icecast://source:YOUR_PASSWORD@

(Don't forget to replace by your raspberry pi local ip)

You have now a feed readable from

How to cast?

To cast what you want to a chromecast, have a look on Pychromecast Of course, you need python3:

$ sudo apt-get install python3

And a tiny python script:

import time
import pychromecast
import urllib.request

stream_url = ''
chromecasts = pychromecast.get_chromecasts()
cast = next(cc for cc in chromecasts if cc.device.friendly_name == "Salon")
mc = cast.media_controller
while urllib.request.urlopen(stream_url).getcode() != 200:
    print('Waiting for stream up')

mc.play_media(stream_url, 'audio/mp3')

And ... it's a kind of magic:

$ /usr/bin/ffmpeg  -f libcdio -ss 0 -i /dev/cdrom -acodec libmp3lame -ab 48k -bufsize 15 -ac 1 -content_type audio/mpeg -f mp3  icecast://source:SOURCE_PASSWORD@ & /usr/bin/python3 /home/pi/audio/

Bonus: autostart on cd insertion

We will use an udev rule, for example in a /etc/udev/rules.d/99-cd-audio-processing.rules rule:

SUBSYSTEM=="block", KERNEL=="sr0", ACTION=="change", RUN+="/home/pi/audio/ &"

Reboot, and you're ready :)

You can’t perform that action at this time.