Skip to main content

Cast audio from pipewire to chromecast device.

Project description

P-Cast

Cast anything you can hear on your Linux desktop to any Chromecast‑compatible speaker, TV or Nest device — live, with ~3 s latency.

P‑Cast captures audio directly from PipeWire / PulseAudio, encodes it with FFmpeg and exposes the result as an HLS live stream that is played by Chromecast.

Casts local audio-device to chromecast compatible device.

Quick start

git clone https://github.com/GenessyX/p-cast
cd p-cast

uv run python run.py

Send audio to P‑Cast (set it as default sink or route an app explicitly).

Features

  • Virtual sink - creates virtual null sink P-Cast on the fly.
  • Automatic device discovery – finds the first Chromecast on your LAN via mDNS.
  • On‑the‑fly transcoding – AAC @ 256 kbps by default (customisable via env vars).
  • Live HLS – 0.5 s segments; Chromecast buffers 3 -> ~3 s end‑to‑end delay.
  • Volume follow – changes to the PipeWire sink volume are mirrored to the Chromecast.
  • Tiny footprint – single Python process + FFmpeg child; no browser or GUI required.
  • Optional reconnection guard – a p-cast-stream.conf snippet keeps the capture stream pinned to the chosen device.

How it works (TL;DR)

  1. run.py starts Granian and serves the Starlette app on :3000.

  2. app.py

    1. discovers a Chromecast (cast.find_chromecast),
    2. creates a null sink named P‑Cast (device.SinkController),
    3. launches FFmpeg (ffmpeg.create_ffmpeg_stream_command) to read from P‑Cast.monitor and write HLS segments to a temp dir,
    4. mounts that dir at /stream.
  3. After 2 s the Chromecast receives http://<host>:3000/stream/index.m3u8 via the Media Controller and starts buffering.

  4. A background task listens for pactl volume‑change events and calls Chromecast.set_volume(...).

Everything runs in a single Python process; FFmpeg is the only external binary.

Requirements

Component Purpose
Linux w/ PipeWire audio capture
Python ≥ 3.12 application runtime
FFmpeg ≥ 6.1 encoding & HLS muxing
Chromecast playback device on same LAN

Dependencies are declared in pyproject.toml. The examples below use uv but regular pip works just as well.

uv run python run.py

Optional: keep PipeWire from re‑connecting to another device

Unplugging headphones or switching default sink can make PipeWire migrate all streams – including the monitor the server is recording – to a new sink, resulting in streaming input from switched device to the Chromecast. If that annoys you, add the supplied pipewire config:

mkdir -p ~/.config/pipewire/pipewire-pulse.conf.d
cp ./p-cast-stream.conf ~/.config/pipewire/pipewire-pulse.conf.d/p-cast-stream.conf
systemctl --user restart pipewire

The file sets:

node.dont-reconnect = true        # stay on the chosen device
node.latency        = "64/48000"  # optional, lowers internal latency

🔊 Audio Delay: PipeWire to Chromecast

The minimum practical delay between audio captured from a PipeWire sink and audio output on a Chromecast device is approximately 3 seconds.

This delay is primarily due to how Chromecast handles HLS streaming, which includes:

  1. Buffering: Chromecast typically buffers 3 full segments before beginning playback.

  2. Playlist polling interval: The device refreshes the playlist based on the #EXT-X-TARGETDURATION value, which defines the expected segment duration and how frequently the .m3u8 file is reloaded.

  3. Segment duration limitations: While the Google Chromecast documentation states:

    #EXT-X-TARGETDURATION — How long in seconds each segment is. This also determines how often we download/refresh the playlist manifest for a live stream. The Web Receiver Player does not support durations shorter than 0.1 seconds.

    In practice, Chromecast cannot reliably handle #EXT-X-TARGETDURATION values below 1 second. Attempting to use smaller values (e.g., 0.25s) may result in playback stop.

  4. Comparison with VLC: Media players like VLC can handle much shorter segment durations (e.g., 0.25s) and respond to playlist updates more aggressively, leading to lower latency compared to Chromecast.


💡 Summary

Player Minimum stable segment duration Behavior
Chromecast ~1 second Buffers 3 segments, ~3s delay
VLC / hls.js 0.25–0.5 seconds Can start playback much faster

Known limitations

  • Only the first Chromecast discovered is used. Open a PR to add a selector!
  • Audio only. Support for dummy video tracks is stub‑bed out in ffmpeg.py.
  • Tested on Manjaro Linux / PipeWire 1.4.1;
  • 3+ seconds delay.

Roadmap

  • Configuration with envs:

    Variable Default Description
    PCAST_BITRATE 256k AAC bitrate fed to FFmpeg
    PCAST_SAMPLE_RATE 48000 Sampling rate (Hz)
    PCAST_HLS_FORMAT mpegts mpegts or experimental fmp4
    PCAST_SINK_NAME P-Cast Name of the null sink

    See config.py for details.

  • Multiple chromecast devices support.

  • Package with uvx (uv tool).

  • Enhance repository structure.

  • Qt tray app to control chromecast device (pause/play).

License

GPL-3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

p_cast-1.0.0.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

p_cast-1.0.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file p_cast-1.0.0.tar.gz.

File metadata

  • Download URL: p_cast-1.0.0.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for p_cast-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0705656c4c84e639903f016fc20999116f940da9fdcb58614847b212c49defde
MD5 e7759ad168c520f732ed99a2c5bbae34
BLAKE2b-256 527b49b6c104a4d38da780498e61d7ec3e328fc55712d7ad12af31c304fee827

See more details on using hashes here.

File details

Details for the file p_cast-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: p_cast-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for p_cast-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8863cf669300153560e18c85c0e4c6124ed4e58bee56268d2eebd5360d7f7dfc
MD5 49bfdbb053d37505f6cd90786df14dd1
BLAKE2b-256 261d5db9e143c212fe199dd20bbd19fa8f71627aad8b3047a507bf5f8019315f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page