Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Cast macOS and Linux Audio/Video to your Google Cast and Sonos Devices

License

NotificationsYou must be signed in to change notification settings

muammar/mkchromecast

Repository files navigation

I don't have too much time recently to take care of the project. If you would be interested in helping, please comment on#398

Mkchromecast

LicensePyPI - Python VersionnodeDownloadsGitHub release

This is a program to cast yourmacOS audio, orLinux audio to yourGoogle Cast devices or Sonos speakers. It can alsocast video files.

It is written for Python3, and it can stream vianode.js,parec (Linux),orffmpeg.Mkchromecast is capable of using lossy and lossless audioformats provided thatffmpeg orparec (Linux) are installed. It alsosupportsMulti-room groupplayback, and24-bit/96kHz high audio resolution.Additionally, a system tray menu is available.

By default,Mkchromecast streams withnode.js (orparec inLinux)together withmp3 audio coding format at a sample rate of44100Hz andaverage bitrate of192k. These defaults can be changed using the--sample-rate and-b flags. It is useful to modify these parameters whenyour wireless router is not very powerful, or in the case you don't want todegrade the sound quality. For more information visit thewiki, and theFAQ.

You can optionally installffmpegmore informationhere).Linux users also can configureALSA to captureaudio. Note that sometimesthe lag between playing a song and hearing may be up to 8 seconds for certainbackends.

Tell me more about it

To have an idea of usingMkchromecast from consolecheck thisgif.

Mkchromecast provides abeta system tray menu. It requires you toinstallPyQt5. For more information check theRequirements andInstall sections.

This is what the system tray menu looks like:

macOS

Example

Linux

Check these images:

Sonos support

If you have Sonos speakers, you can play whatever you are listening to in yourcomputer withMkchromecast. To add Sonos support, install thesoco pythonmodule:

pip3 install soco

Contribute

If you want to contribute, you can help byreportingissues or bycreating pullrequests with yourdevelopments/improvements. If your case is the latter, visitDevelopment sectionin the Wiki.

Requirements:

macOS

In order to useMkchromecast you need the following software to stream withnode.js:

  • Python3.
  • pychromecast.
  • psutil.
  • mutagen.
  • BlackHole
  • PyQt5 (optional if you want to use the system tray menu).

For more control, you needffmpeg as backend. In that case install thefollowing:

  • flask (optional).
  • ffmpeg (optional).
  • youtube-dl (option if you plan to cast youtube URLs orsupportedwebsites).

Linux

  • Pulseaudio.
  • Pavucontrol.
  • Python3 (if using the official debian package).
  • pychromecast.
  • psutil.
  • mutagen.
  • flask.
  • vorbis-tools.
  • sox.
  • lame.
  • flac.
  • faac.
  • ffmpeg (optional).
  • PyQt5 (optional if you want to use the system tray menu).
  • youtube-dl (option if you plan to cast youtube URLs orsupportedwebsites).
  • soco (this module adds Sonos support to Mkchromecast).

For those who don't like Pulseaudio, it is possible tocast usingALSA. In that case therequirements are:

  • alsa-base
  • alsa-utils
  • alsa-utils
  • Python3 (if using the official debian package).
  • pychromecast.
  • psutil.
  • mutagen.
  • flask.
  • vorbis-tools.
  • sox.
  • lame.
  • flac.
  • faac.
  • ffmpeg.
  • PyQt5 (optional if you want to use the system tray menu).
  • youtube-dl (option if you plan to cast youtube URLs orsupportedwebsites).
  • soco (this module adds Sonos support to Mkchromecast).

Install

There are two ways of installing this application:

  1. Using thebinaries.
  2. Fromsources.

Binaries

macOS

There is a standalone application formacOS users. You need to drag it to your/Applications/ folder.

Download the latest dmghere.You need also toinstallBlackHole.

Homebrew Cask

If you are using homebrew, it is possible to install the binary as follows:

brew install --cask mkchromecast

If you find any problem with the application, pleasereport ithere.

Linux

Mkchromecast is available in theofficial Debianrepositories. To installit, just do:

apt install mkchromecast

Download the latestdeb packagehere, and install it asfollows:

sudo apt -f install ./mkchromecast_$VERSION_all.deb

where$VERSION = X.Y.Z-Rev,e.g.:0.2.6-1.

This should work in Debian Unstable and Testing. I would appreciate Ubuntutesters as well. If you find any problems, pleasereport ithere.

If you experience other problems related to dependencies, pleasediscuss themhere or open a new issue.

Additionally, there are two dependency packages for pulling pulseaudio or ALSAdependencies:

apt-get install mkchromecast-alsa (ALSA users)

or

apt-get install mkchromecast-pulseaudio (Pulseaudio users)

From sources

To installMkchromecast, clone this repository:

git clone https://github.com/muammar/mkchromecast.git --depth 1

Or you may download one of thestable releaseshere, and unzip the file.

Arch Linux

Mkchromecast is available at the AUR :

#install with aurmanaurman -S mkchromecast
#install with aurutilsaur sync mkchromecast

If you get the errorcannot import name 'DependencyWarning' in Arch Linux,please check issue#31.

Python

To install python requirements use therequirements.txt file shipped inthis repository:

pip install -r requirements.txt

Note: if this step fails, maybe you need to run the installation withsudo as shown below. However, before installing using this method verify whya regular user cannot install these requirements.

sudo pip install -r requirements.txt

Linux users can try to install these python requirements using the packagemanagers coming with their distributions.

Example for Debian based distros:

sudo apt-get install python3.6 python3-pip python3-pychromecast python3-flask python3-psutil python3-setuptools python3-mutagen python3-gi vorbis-tools sox lame flac faac opus-tools

Note: ifpython3-pychromecast is not available in your repository,follow instructions in#9.

BlackHole (macOS users only)

For installing BlackHole you can checkhttps://github.com/ExistentialAudio/BlackHoleand just download thelatest dmgfile.

If you haveHomebrew you can usebrewcask as follows:

brew install --cask blackhole

By default, the sample rate in BlackHole is set to44100Hz. If you desireto stream at higher sample rates follow theinstructions in thewiki.

Note: re-sampling to higher sample rates is not a good idea. It was indeedan issue in chromecast audio devices. Seethis thread.Therefore, if you want to go beyond44100Hz you have tocapture the sound ata higher sample rate.

ffmpeg

The easiest way of installingffmpeg is using a package manager,e.g.: brew,macports or fink. Or in the case ofLinux,e.g.: apt, yum, or pacman.

macOS

I will briefly describe the case of Homebrew here. First, you will needHomebrew installed in your machine:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once Homebrew is ready, you can installffmpeg. As stated in theffmpegwebsite, and for beingable to use all audio coding formats inMkchromecast, it is better toinstallffmpeg with the following options enabled:

brew install ffmpeg --with-fdk-aac --with-tools --with-freetype --with-libass --with-libvorbis --with-libvpx --with-x265 --with-opus
Linux

As I use Debian, the way of installingffmpeg is:

apt-get install ffmpeg

Audio coding formats available withparec andffmpeg backends

Audio coding formatDescriptionNotes
mp3MPEG Audio Layer III (default)Lossy compression format (default bitrate: 192k)
oggOgg VorbisLossy compression format (default bitrate: 192k)
aacAdvanced Audio Coding (AAC)Lossy compression format (default bitrate: 192k)
opusOpusLossy compression format (default bitrate: 192k)
wavWaveform Audio File FormatLossless format (HQ sound)
flacFree Lossless Audio CodecLossless format (HQ sound)
PyQt5

These Python bindings are needed if you intend to use the system tray menu.Sometimespip is able to installPyQt5 andpip install pyqt5 is enough.

If this does not work for you, I suggest you to install it using a packagemanager.

macOS

Example with Homebrew:

brew install pyqt5 --with-python3
Linux
  • Debian
apt-get install python3-pyqt5

or if you desire it you can do it yourself from the sources.

Updating

To updateMkchromecast sources, just get into the cloned directory and:

git pull

or if you prefer it, you can just pass the--update argument toMkchromecast:

bin/mkchromecast --update

If you are using themacOS application:

  1. Click onCheck For Updates.
  2. If there are new versions, you will be prompted todownload the latestdmg.
  3. Replace themkchromecast.app in your/Applications/ directory.

Linux users need to either perform aapt-get upgrade ordownload thelatest deb here, anddpkg -i mkchromecast_$VERSION_all.deb.

Usage

Audio

Get into the clonedMkchromecast directory and execute:

bin/mkchromecast

This will launchMkchromecast usingnode.js (orparec forLinuxusers), and will do the streaming part together with themp3 audio codingformat.node.js works decently but the server may tend tofail under certaincircumstances. In such a case,Mkchromecast is able to restart thestreaming/casting process automatically. So, some hiccups are expected.

Note: most of the steps described herein are the same formacOS andLinuxusers. However, if you launch the command above inLinux, the process isless automatized. InLinux, you need to select withpavucontrol the sinkcalledMkchromecast to stream unless you are usingALSA.See thewiki for more information. tl;dr?, justcheck the gif below.

Example of using mkchromecast

Note: the cast process is independent from the selection of the pulseaudiosink. This means thatMkchromecast will tell the cast device to listen yourcomputer but no sound will be heard until you select the sink. For ALSA users, thisdoes not apply.

Using theffmpeg backend withMkchromecast installed from sources

Below an example usingmp3:

bin/mkchromecast --encoder-backend ffmpeg

Withffmpeg you can modify the codec:

bin/mkchromecast --encoder-backend ffmpeg -c aac

change the bitrate and sample rate:

bin/mkchromecast --encoder-backend ffmpeg -c mp3 -b 128 --sample-rate 31000

check the sectionBlackHole (macOS usersonly)for more about sample rates.

You also can set the host ip manually which is a useful option when having morethan one active network connection or when the automatically ip detection fails:

bin/mkchromecast --host 192.168.1.1
Other examples withMkchromecast installed using the debian package

To cast usingparec andwav audio coding format:

mkchromecast -c wav

There is also an option to change thebitrate, and in this case withffmpeg:

mkchromecast --encoder-backend ffmpeg -c ogg -b 128

and another one to change the sampling rate:

mkchromecast --encoder-backend ffmpeg -c ogg -b 128 --sample-rate 48000
UsingMkchromecast from the system tray

To launch it:

bin/mkchromecast -t

or

mkchromecast -t

The system tray application can perform all the actions from the aforementionedcommands. To get an idea, please check theYoutube videohere.

Playing Youtube URLs in Google Cast devices

You can play Youtube URLs (orothersites headlessly fromthe command line:

bin/mkchromecast -y https://www.youtube.com/watch\?v\=NVvAJhZVBT

To use this function, you need to installyoutube-dl. In macOS, this can bedone 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 onlyURLs overhttps 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:

  1. Casting using MPD in the case you have already ahttp streaming source.
  2. Casting a radio station. A list of stations to try:https://ponyvillefm.com/servers

Example:

bin/mkchromecast --source-url http://192.99.131.205:8000/pvfm1.ogg -c ogg --control

As it can be seen above,the codec has to be specified with the-c flag.

Note:.m3u or.pls are not yet supported.

Controlling the Google Cast's volume and pause/resume options

You can control the volume of your Google Cast device by launchingMkchromecast with the option--control:

bin/mkchromecast --encoder-backend ffmpeg -c ogg -b 320 --control

This will allow you to pressu andd keys forvolume upandvolume down respectively.

The system tray has a window with a volume slider to dovolume up andvolume down.

High quality audio

Mkchromecast lets you cast using24-bit/96kHz high audio resolution. Thisis themaximum chromecast audio capability. The supported codecs are:wavandflac. In spite of the fact thataac can use96000Hz sample rate, thebitrate corresponds to that of a lossy data compression format. Therefore, thefollowing combinations can achieve this24-bit/96kHz capability:

  • wav +96000Hz sample rate.
  • flac +96000Hz sample rate.

References:

Video

You can now cast videos to your Google cast usingMkchromecast. This feature works both withnodeandffmpeg backends and from command line. In the future, they may be a graphical interfacefor this process.See this project.

  • Cast a file from your computer to your chromecast:
bin/mkchromecast --video -i "/path/to/file.mp4"
bin/mkchromecast --video -i "/path/to/file.mp4" --encoder-backend node

Note: the format of the file can be whatever is supported byffmpeg and not exclusively mp4.

  • Subtitles
bin/mkchromecast --video -i "/tmp/Homeland.S06E01.Fair.Game.1080p.AMZN.WEBRip.HEVC.DD5.1.x265.mkv" --subtitles /tmp/Homeland.S06E01.Fair\ Game.HDTV.x264-BATV.en.HI.srt
  • Set the resolution
bin/mkchromecast --video --resolution 4k -i /path/to/myvideo.something --subtitles /path/to/my.srt
  • Cast from a source url:
bin/mkchromecast --source-url http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4 -c mp4 --volume --video
  • Youtube Video
bin/mkchromecast -y https://www.youtube.com/watch\?v\=VuMBaAZn3II --video

Killing the application

To killMkchromecast when you run it from console, just pressCtrl-C orq key to quit (when--control flag is passed).

When launching from system tray, use theQuit 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 newerversions of pychromecast.
  • When casting videos using thenode backend, it is not possible touse neither the--subtitle nor the--seek flags.
  • When casting to Sonos the only codecs supported are:mp3, andaac.I won't givewma support. Apparently there is a way to playwav, andogg that I will try to implement later.
macOS
  • Mkchromecast v0.3.6 cannot connect to selected chromecast when there aremore than one available. In that case, you need to use the application fromsources or build the application as shownhere.
Linux
  • When usingparec andlame encoder, the delay between audio played andlistened can be up to 8 seconds. I suggest you to use something differentthan mp3.

You can also check theFAQfor more information.

TODO

  • Verify all exceptions when the system tray menu fails.
  • Sonos: add support to different available flags.
  • Sonos: add Equalizer in the controls.

[8]ページ先頭

©2009-2025 Movatter.jp