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
Port Configuration
By default, a random free port is chosen. You can specify a fixed port if needed (e.g. for firewall rules):
terminalcast my_video.mp4 --port 8080
Alternatively, set the environment variable TERMINALCAST_PORT:
export TERMINALCAST_PORT=8080
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:
TERMINALCAST_TMP_DIRenvironment variable/dev/shm(RAM disk on Linux)/var/tmp- 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 and a specific port
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"],
port=8080
)
# 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:
- Clone the repository
- Install dependencies: This will install the project in editable mode with all development tools.
make install - Install the pre-commit hook: This will run quick checks before each commit.
pre-commit install - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file terminalcast-1.3.0.tar.gz.
File metadata
- Download URL: terminalcast-1.3.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21eb9ede2558b725ffcb5a9301f88876274fddb42ff22290f8cbac734c9c806e
|
|
| MD5 |
1118958cff219f6cb3d5b656ffe872e6
|
|
| BLAKE2b-256 |
8da89bedab5a800fa32d52c3ca513a2031244a428f1182c90ab5452ceb77c9cb
|
Provenance
The following attestation bundles were made for terminalcast-1.3.0.tar.gz:
Publisher:
python-publish.yml on vanadinit/terminalcast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
terminalcast-1.3.0.tar.gz -
Subject digest:
21eb9ede2558b725ffcb5a9301f88876274fddb42ff22290f8cbac734c9c806e - Sigstore transparency entry: 803416057
- Sigstore integration time:
-
Permalink:
vanadinit/terminalcast@e461703b11769db85d55ad753576e970af3278af -
Branch / Tag:
refs/tags/1.3.0 - Owner: https://github.com/vanadinit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e461703b11769db85d55ad753576e970af3278af -
Trigger Event:
release
-
Statement type:
File details
Details for the file terminalcast-1.3.0-py3-none-any.whl.
File metadata
- Download URL: terminalcast-1.3.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e91bdeaeda0297e29f63ece38256ce99d5dfa573fdc1a40c2753f2efcfbe43f
|
|
| MD5 |
6d3debd1fd243c426389d35394a7ef5b
|
|
| BLAKE2b-256 |
0703b95cbaef41c384e78a1eacef3b36b769e53d41f49283c487706b6b3255c9
|
Provenance
The following attestation bundles were made for terminalcast-1.3.0-py3-none-any.whl:
Publisher:
python-publish.yml on vanadinit/terminalcast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
terminalcast-1.3.0-py3-none-any.whl -
Subject digest:
1e91bdeaeda0297e29f63ece38256ce99d5dfa573fdc1a40c2753f2efcfbe43f - Sigstore transparency entry: 803416063
- Sigstore integration time:
-
Permalink:
vanadinit/terminalcast@e461703b11769db85d55ad753576e970af3278af -
Branch / Tag:
refs/tags/1.3.0 - Owner: https://github.com/vanadinit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e461703b11769db85d55ad753576e970af3278af -
Trigger Event:
release
-
Statement type: