This is a program to cast your macOS audio, or Linux audio to your
Google Cast devices or Sonos speakers. It can also cast video files.
It is written for Python3, and it can stream via node.js, parec (Linux),
ffmpeg, or avconv. Mkchromecast is capable of using lossy and lossless
audio formats provided that ffmpeg, avconv (Linux), or parec
(Linux) are installed. It also supports Multi-room group
playback, and
24-bit/96kHz high audio resolution.
Additionally, a system tray menu is available.
By default, Mkchromecast streams with node.js (or parec in Linux)
together with mp3 audio coding format at a sample rate of 44100Hz and
average bitrate of 192k. These defaults can be changed using the
--sample-rate and -b flags. It is useful to modify these parameters when
your wireless router is not very powerful, or in the case you don't want to
degrade the sound quality. For more information visit the
wiki, and the
FAQ.
You can optionally install ffmpeg or avconv (the latter only supported in Linux,
more information
here).
Linux users also can configure ALSA to capture
audio. Note that sometimes
the lag between playing a song and hearing may be up to 8 seconds for certain
backends.
Tell me more about it
To have an idea of using Mkchromecast from console check this
gif.
Mkchromecast provides a beta system tray menu. It requires you to
install PyQt5. For more information check the
Requirements and
Install sections.
If you have Sonos speakers, you can play whatever you are listening to in your
computer with Mkchromecast. To add Sonos support, install the soco python
module:
If you get the error cannot import name 'DependencyWarning' in Arch Linux,
please check issue #31.
Python
To install python requirements use the requirements.txt file shipped in
this repository:
pip install -r requirements.txt
Note: if this step fails, maybe you need to run the installation with
sudo as shown below. However, before installing using this method verify why
a regular user cannot install these requirements.
sudo pip install -r requirements.txt
Linux users can try to install these python requirements using the package
managers coming with their distributions.
By default, the sample rate in BlackHole is set to 44100Hz. If you desire
to stream at higher sample rates follow the instructions in the
wiki.
Note: re-sampling to higher sample rates is not a good idea. It was indeed
an issue in chromecast audio devices. See this thread.
Therefore, if you want to go beyond 44100Hz you have to capture the sound at
a higher sample rate.
ffmpeg or avconv
The easiest way of installing ffmpeg is using a package manager, e.g.: brew,
macports or fink. Or in the case of Linux, e.g.: apt, yum, or pacman.
macOS
I will briefly describe the case of Homebrew here. First, you will need
Homebrew installed in your machine:
Once Homebrew is ready, you can install ffmpeg. As stated in the ffmpeg
website, and for being
able to use all audio coding formats in Mkchromecast, it is better to
install ffmpeg with the following options enabled:
Replace the mkchromecast.app in your /Applications/ directory.
Linux users need to either perform a apt-get upgrade or download the
latest deb here, and dpkg -i mkchromecast_$VERSION_all.deb.
Usage
Audio
Get into the cloned Mkchromecast directory and execute:
bin/mkchromecast
This will launch Mkchromecast using node.js (or parec for Linux
users), and will do the streaming part together with the mp3 audio coding
format. node.js works decently but the server may tend to fail under certain
circumstances. In such a case, Mkchromecast is able to restart the
streaming/casting process automatically. So, some hiccups are expected.
Note: most of the steps described herein are the same for macOS and Linux
users. However, if you launch the command above in Linux, the process is
less automatized. In Linux, you need to select with pavucontrol the sink
called Mkchromecast to stream unless you are using ALSA.
See the wiki for more information. tl;dr?, just
check the gif below.
Note: the cast process is independent from the selection of the pulseaudio
sink. This means that Mkchromecast will tell the cast device to listen your
computer but no sound will be heard until you select the sink. For ALSA users, this
does not apply.
Using the ffmpeg backend with Mkchromecast installed from sources
You also can set the host ip manually which is a useful option when having more
than one active network connection or when the automatically ip detection fails:
bin/mkchromecast --host 192.168.1.1
Other examples with Mkchromecast installed using the debian package
To cast using parec and wav audio coding format:
mkchromecast -c wav
There is also an option to change the bitrate, and in this case with ffmpeg:
To use this function, you need to install youtube-dl. In macOS, this can be
done with homebrew: brew install youtube-dl. In Debian based distros:
apt-get install youtube-dl.
Note: you may need to enclose the URL between quotation marks, and only
URLs over https are supported.
Playing source URLs in Google Cast devices
You can play any source URLs headlessly from the command line:
bin/mkchromecast --source-url SOURCE_URL
This option is useful for:
Casting using MPD in the case you have already a http streaming source.
This will allow you to press u and d keys for volume up
and volume down respectively.
The system tray has a window with a volume slider to do volume up and volume down.
High quality audio
Mkchromecast lets you cast using 24-bit/96kHz high audio resolution. This
is the maximum chromecast audio capability. The supported codecs are: wav
and flac. In spite of the fact that aac can use 96000Hz sample rate, the
bitrate corresponds to that of a lossy data compression format. Therefore, the
following combinations can achieve this 24-bit/96kHz capability:
You can now cast videos to your Google cast using Mkchromecast. This feature works both with node
and ffmpeg backends and from command line. In the future, they may be a graphical interface
for this process. See this project.
Cast a file from your computer to your chromecast:
To kill Mkchromecast when you run it from console, just press
Ctrl-C or q key to quit (when --control flag is passed).
When launching from system tray, use the Quit button in the system tray.
More help
To get more help:
bin/mkchromecast -h
or when installing the debian package:
mkchromecast -h
Known issues
General
Mkchromecast's versions lower than 0.3.7 cannot operate with newer
versions of pychromecast.
When casting videos using the node backend, it is not possible to
use neither the --subtitle nor the --seek flags.
When casting to Sonos the only codecs supported are: mp3, and aac.
I won't give wma support. Apparently there is a way to play wav, and
ogg that I will try to implement later.
macOS
Mkchromecast v0.3.6 cannot connect to selected chromecast when there are
more than one available. In that case, you need to use the application from
sources or build the application as shown
here.
Linux
When using parec and lame encoder, the delay between audio played and
listened can be up to 8 seconds. I suggest you to use something different
than mp3.