
Show HN: Control Chromecasts from Linux - this_machine
https://github.com/alexdelorenzo/chromecast_mpris
======
balloob
Author of pychromecast here, the underlying library that this project uses to
control the Chromecast.

I wrote this lib initially for use in Home Assistant, [https://www.home-
assistant.io](https://www.home-assistant.io)

For Home Assistant I made a rule that all device drivers are stand-alone Home
Assistant agnostic Python packages. That way more projects can use it.

Glad to see that strategy is working out and it powering projects like this

~~~
atomi
It would be incredible if there was a way to use mpsyt to watch Youtube videos
with your library.

~~~
msla
It's possible if you hook something running Kodi up to your TV.

Here's some example code I wrote, in the form of a few ZSH shell scripts:

[https://github.com/chbarts/kodi-command-
line](https://github.com/chbarts/kodi-command-line)

The logic should port nicely to other languages. In particular, it shows how
to do things like playing a YouTube video using either the URL or just the
hash, plus, of course, a way to play videos on the computer you're running the
commands from.

------
liability
If you don't want a Google device on your LAN and are willing to put in a
little bit more work for that, I've found that remotely controlling an
instance of mpv over the JSON IPC interface works well for me. I can send it
URLs from the web or paths to local files. My client for this isn't currently
public, but it's a rather easy interface that some of you may find it easy
enough to integrate into your other systems.

(Note that it only listens on a Unix socket. With socat you can redirect that
to a TCP socket though, preferably listening on a wireguard interface to keep
the rest of your LAN from accessing it, since there's otherwise no security.)

Definitely not for everybody, but perhaps suitable for some.

[https://mpv.io/manual/master/#json-ipc](https://mpv.io/manual/master/#json-
ipc)

~~~
miccah
This is my preference as well! I even wrote an Android client app / Python
server to control it from my phone.

[https://github.com/mcastorina/mpv-remote-
app](https://github.com/mcastorina/mpv-remote-app)

~~~
MayeulC
This looks useful and to the point. Would you consider submitting it to
f-droid?

------
gala8y
OT, but i had an idea yesterday... will explain in UX language: would it be
possible to send video to chromecast-like device and 'leave sound on mobile
device' to be able to listen on bluetooth connected headphones while watching
on big screen?

~~~
Falling3
I've thought about the same thing, but I don't think it's feasible because you
essentially need to play the video in both places and ensure it stays in sync.
The easy solution is to hook up a Bluetooth transmitted to your TV.

~~~
gala8y
I know, but it _could_ use one stream and send audio to mobile via LAN.
Syncing would be an issue, though. Overengineering at its best. ;)

------
ebg13
I can't tell from this project's readme how to actually play things. It has an
instruction for connecting to your chromecast...ok, and then what?

In the past I've used
[https://github.com/keredson/gnomecast](https://github.com/keredson/gnomecast)
which is a standalone simple media player that transcodes if needed and
streams to my Chromecast. Thoughts on what this provides that's better?

~~~
this_machine
While you have chromecast_mpris running, you can use an MPRIS client to issue
the OpenUri method[1]. Here's an example:

    
    
        $ export URL="http://ccmixter.org/content/gmz/gmz_-_Parametaphoriquement.mp3"
        $ playerctl -p My_Chromecast open "$URL"
    

This will cast a song to the Chromecast named "My_Chromecast". I forgot that
OpenUri was implemented in the project because I typically cast from other
devices and programs, but I'll include it in the README.

> _Thoughts on what this provides that 's better?_

People tend to use catt or castnow to cast from the command-line. I wrote
about using VLC to cast to the Chromecast[2], but I wouldn't recommend it
unless you're watching something that you need VLC for.

[1] [https://specifications.freedesktop.org/mpris-
spec/2.2/Player...](https://specifications.freedesktop.org/mpris-
spec/2.2/Player_Interface.html#Method:OpenUri)

[2]
[https://alexdelorenzo.dev/linux/2020/03/14/pipes](https://alexdelorenzo.dev/linux/2020/03/14/pipes)

------
axaxs
Thanks for this, I can't wait to test it out.

Are there other ways to control chromecasts from Linux? I used to be able to
cast straight from Chromium, but that hasn't worked for me in at least a
couple years.

~~~
ce4
VLC has a native client afaik.

Edit: included since v3.0

[https://www.videolan.org/developers/vlc-
branch/NEWS](https://www.videolan.org/developers/vlc-branch/NEWS)

~~~
londons_explore
The VLC client is "barebones" \- even simple functionality like adjusting the
volume is missing. If the network connection drops, the chromecast stops
playing (regular chromecast would continue). There is no support for
subtitles, alternate audio/video tracks, audio effects, video playback speed,
or pretty much anything else.

Seeking is supported tho, as are audio-only files.

~~~
kelnos
> _If the network connection drops, the chromecast stops playing (regular
> chromecast would continue)_

How would you expect the video bits to get from the machine running VLC to the
chromecast if the network drops? Not sure what you mean by "regular
chromecast", but if the network connection between the chromecast and the
video source is lost, you lose playback. That's true if you're watching
YouTube videos or Netflix, or if you're using any other app to cast something
from your local network.

~~~
mholt
Only if it's lost for longer than was buffered. Most decent streaming clients
-- even YouTube -- will buffer ahead and keep playing while attempting to
restore connectivity.

Speaking of which, the casting with VLC also has major buffering problems.
Even casting a low-def video directly from an SSD to a Chromecast Ultra (over
ethernet!) it will buffer for about 1-2 minutes for every 5 seconds of
playback.

------
StavrosK
This is nice, I've been using catt mapped to the media keys via the native
window manager shortcuts, but this seems easier to set up.

~~~
this_machine
I do something similar with chromecast_mpris. I have my media keys mapped to
Plasma's Media Controller, which uses MPRIS in the background. Works well for
me, and you don't have to wait for catt to launch and find your Chromecast
each time.

------
markbnj
Shameless threadjack: does anyone know a way to cast _to_ a linux or windows
desktop? We use chromecast on all our entertainment video monitors, but
sometimes I would like to hang on the couch in my office and cast a video to
my desktop monitor.

~~~
pmontra
Maybe scrcpy is enough for you.

[https://github.com/Genymobile/scrcpy](https://github.com/Genymobile/scrcpy)

If opening a browser tab is all you need any tab syncing app / service will
do. I use kdeconnect / gsconnect so I don't have to rely on a 3rd party
service, Google and Mozilla included.

~~~
markbnj
Ah this is a good idea, I hadn't thought of approaching it that way. Having
basic pause/back/forward media controls would also be nice, but they should
work if the browser location gets updated right?

------
mijoharas
sorry to somewhat hijack this thread, but does anyone know a way to stream
from linux to a miracast target?

I have a fire stick that I believe supports miracast, and periodically check
if there is linux software that will allow me to stream as a source.

Last time I checked miraclecast[0] seemed to be somewhat broken. Has anyone
had any luck?

[0]
[https://github.com/albfan/miraclecast](https://github.com/albfan/miraclecast)

------
baby-yoda
does chromecast still require WAN access to operate?

~~~
m-p-3
I believe so, and it's less than useful on network with a captive portals like
hotel rooms.

At least the upcoming Chromecast with Google TV comes with a remote, so you
should be able to interact with the captive portal and use it that way.

~~~
fragmede
While the chromecast's inability to work with captive portals is it's own
problem, they make tiny wifi routers, half as tall and twice as thick as a
smartphone, and they're cheap. If you find yourself facing captive portals
more than once, I'd recommend buying one so you can use your Chromecast in
hotel rooms, among other use cases.

~~~
m-p-3
I already have one from TP-Link, but having the new Chromecast would allow me
to shrink down on hardware even more.

------
jowsie
Does this also allow you to cast arbitrary media to the Chromecast? I couldn't
tell from the readme.

~~~
input_sh
I've been using catt
([https://github.com/skorokithakis/catt](https://github.com/skorokithakis/catt))
for years for that purpose. Basically:

    
    
        pip3 install catt
    

And then:

    
    
        catt cast <any image/song/video/URL supported by youtube-dl>

~~~
SyncOnGreen
[https://airflow.app/](https://airflow.app/) is worth mentioning - paid
software (sadly Windows/macOS only) but works with everything you throw at it,
transcodes unsupported codecs seamlessly and has great UI with remote control
via an app.

------
29athrowaway
An unpopular choice for general purpose streaming: Steam Link.

You can install the Steam Link on a smart TV and your computer (including
Linux), switch the Steam window and stream whatever you want to stream.

------
zerop
Any way to cast zoom calls from my android zoom app to TV via Chromecast ?

~~~
m-p-3
You can cast your device's screen, but you'll still have to rely on the
device's camera and mic.

You'll probably want to avoid outputting the sound on the TV or you'll get a
feedback loop.

And there's going to be a slight delay, which might be annoying with a
realtime conversation.

So it might not be a great idea from the start.

~~~
londons_explore
You'll also end up with 15 fps, high CPU usage, and random hangs... It works,
but isn't really usable...

------
hansjorg
Title says 'from Linux', but the README says 'Linux / *BSD / macOS' under
'Requirements'.

How would this work on macOS?

~~~
this_machine
> _How would this work on macOS?_

Theoretically it should work if you're able to get D-Bus working on macOS.
D-Bus is usually a Linux thing, but it's been ported to other platforms. macOS
isn't included in the title because most macOS users don't have D-Bus
installed.

I included instructions here[1] with URLs to the macOS versions of D-Bus and
PyGObject. I'd be interested in whether you're able get it working.

[1]
[https://github.com/alexdelorenzo/chromecast_mpris#requiremen...](https://github.com/alexdelorenzo/chromecast_mpris#requirements)

