Skip to main content

Cast local videos to your chromecast

Project description

Terminalcast

Command line tool to cast local video files to your chromecast.

Inspired by https://github.com/keredson/gnomecast

Supported media types

Checkout https://developers.google.com/cast/docs/media for your Chromecast model.

Use ffmpeg to convert unsupported files to a supported format:

ffmpeg -i '{input_file}' -metadata title="{title}" -map 0 -c:v {video_codec} -c:a {audio_codec} -c:s copy '{output_file}'

Supported Chromecast versions

In principle this should work with any Chromecast which is supported by https://github.com/home-assistant-libs/pychromecast.

In practice, I discovered that a Chromecast with Google TV enables you to control the player via the remote control, which is very nice.

Installation

pip install terminalcast

Usage

Basic Usage

terminalcast my_video.mp4

Known Hosts

If network discovery fails (e.g. due to network restrictions), you can specify known Chromecast IPs:

terminalcast my_video.mp4 --known-hosts 192.168.1.50,192.168.1.51

Alternatively, set the environment variable TERMINALCAST_KNOWN_HOSTS:

export TERMINALCAST_KNOWN_HOSTS="192.168.1.50,192.168.1.51"
terminalcast my_video.mp4

Temporary File Location

When selecting a different audio track, a temporary file is created. To speed this up, you can specify a directory for these files, ideally a RAM disk. A progress bar will be shown during this process.

The default priority is:

  1. TERMINALCAST_TMP_DIR environment variable
  2. /dev/shm (RAM disk on Linux)
  3. /var/tmp
  4. System default

Example:

export TERMINALCAST_TMP_DIR="/my/fast/disk"
terminalcast my_video.mp4 --audio-title "English"

Using as a Library

You can also use terminalcast as a library in your own projects.

from terminalcast import FileMetadata, TerminalCast, create_tmp_video_file

# 1. Get file metadata
filepath = "my_video.mp4"
media_file = FileMetadata(filepath=filepath)
print(media_file.details())

# 2. Select an audio stream (e.g., the first one)
audio_stream = media_file.audio_streams[0]

# 3. (Optional) Create a temporary file if a different audio track is needed
# This shows a progress bar and can take a callback for progress updates
def my_progress_callback(progress: float):
    print(f"Conversion progress: {progress:.2f}%")

tmp_filepath = create_tmp_video_file(
    filepath=filepath,
    audio_index=audio_stream.index[-1:],
    duration=media_file.duration,
    progress_callback=my_progress_callback
)

# 4. Initialize TerminalCast
# You can pass known_hosts as a list of IPs
tcast = TerminalCast(
    filepath=tmp_filepath or filepath,
    select_ip=False,  # or True for interactive selection, or a specific IP string
    known_hosts=["192.168.1.50"]
)

# 5. Start the server and play
print(f"Casting to: {tcast.cast.cast_info.friendly_name}")
tcast.start_server()
tcast.play_video()

# The video is now playing. The script will block here until playback is active.
# You might want to add logic to handle server shutdown, etc.

Contributing

Contributions are welcome! To set up your development environment:

  1. Clone the repository
  2. Install dependencies: This will install the project in editable mode with all development tools.
    make install
    
  3. Install the pre-commit hook: This will run quick checks before each commit.
    pre-commit install
    
  4. Run all checks: You can run all linters, type checks, and tests manually at any time.
    make check
    

How is it working?

Terminalcast creates a little HTTP Server at your current machine and serves your media file there. Then it tells the Chromecast the play the stream served at your IP with the corresponding path. That's it! (The devil is in the details.)

Terminalcast uses Bottle to create a small app providing the media file. This app is served by Waitress.

On the other hand Terminalcast detects and plays the media via PyChromecast.

For file information and conversion ffmpeg-python is used.

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

terminalcast-1.2.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

terminalcast-1.2.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file terminalcast-1.2.2.tar.gz.

File metadata

  • Download URL: terminalcast-1.2.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for terminalcast-1.2.2.tar.gz
Algorithm Hash digest
SHA256 806c714ed812ace225cd6d5601a73fd53bde2f551d08bddafe853060553497e4
MD5 6b2fde13d6fc6e2ac06047ebf6adb0ee
BLAKE2b-256 c639ff178fccce4b7a20d263c46e758dfad1357b6c33dcfca7eb148676c42530

See more details on using hashes here.

Provenance

The following attestation bundles were made for terminalcast-1.2.2.tar.gz:

Publisher: python-publish.yml on vanadinit/terminalcast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file terminalcast-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: terminalcast-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for terminalcast-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ff7f2de7dd84bd44cdf631efde81dfff38c3921c6a14a49ce838598323db00a8
MD5 dcc0be22a6f3c849ec6470eeb5c66bd1
BLAKE2b-256 b2da83fdd8d5dee3c81192be01fcf08384911c0927afe4343ae5af8b4bfb2d5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for terminalcast-1.2.2-py3-none-any.whl:

Publisher: python-publish.yml on vanadinit/terminalcast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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