Crates.io | tplay |
lib.rs | tplay |
version | 0.6.0 |
source | src |
created_at | 2023-04-15 09:43:09.972187 |
updated_at | 2024-11-09 23:36:59.656109 |
description | A media player that visualizes images and videos as ASCII art directly in the terminal (with sound). |
homepage | |
repository | https://github.com/maxcurzi/tplay |
max_upload_size | |
id | 839857 |
size | 195,832 |
View images, videos (files or YouTube links), webcam, etc directly in the terminal as ASCII. All images you see below are just made by characters on the terminal command line, drawn really fast.
mpv
or vlc
because they're too mainstream.This crate is still in early development, but it already has a lot of features. Here's a list of what it can or can't do:
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Being a Rust crate, you will need to have Rust installed on your system. You can find the installation instructions here.
The following dependencies are also required:
They can be simply installed on Linux with your package manager. See below for more details.
If you're on Linux (Ubuntu), you can install all dependencies with your package manager. First install Rust:
sudo apt install curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Then install tplay
's prerequisite dependencies:
sudo apt install libssl-dev libopencv-dev libstdc++-12-dev clang libclang-dev ffmpeg libavfilter-dev libavdevice-dev libasound2-dev yt-dlp
The crate can run on Windows and all prerequisites (opencv, ffmpeg) can be installed with vcpkg. However, the installation/setup process is lengthy and prone to errors. Performance is also very poor. Save yourself a headache: use WSL and follow the Linux instructions.
You can install it on Arch Linux using aur by running the following commands (using paru):
paru -S tplay-git
The package is not currently available on other Linux distros. With contribution and support it can be made available on other distros as well :).
You can install the tplay
command line tool by running the following command:
# Install the tplay command line tool
cargo install tplay
So that you can run it from anywhere as
tplay <media> [options]
# Clone the repository
git clone https://github.com/maxcurzi/tplay.git
# Change to the project directory
cd tplay
# (optional) Build the project
cargo build
# (optional) Run the tests
cargo test
# Run the project (use --release for faster performance)
cargo run --release -- <media> [options]
By default, the crate uses rodio for audio playback. If you wish to use MPV (libmpv1 libmpv1-dev) as an audio playback backend, you can build/install the crate with:
--features="mpv_0_35" --no-default-features
or
--features="mpv_0_34" --no-default-features
within cargo build
, cargo run
, or cargo install
commands.
MPV support may be dropped in future releases.
tplay <media> [options]
Argument | Description |
---|---|
media |
Name of the file or stream to be processed (required). |
-f , --fps |
Forces a specific frame rate (--fps 23.976). |
-c , --char-map |
Custom lookup character table to use for the output (default: .:-=+*#%@ ). |
-g , --gray |
Start in grayscale mode |
-w , --w-mod |
Experimental width modifier for certain characters such as emojis (default: 1). Use a value of 2 if your char_map is composed of emojis. |
-a , --allow-frame-skip |
Experimental frame skip flag. Try to use it if the playback is too slow. |
-n , --new-lines |
Experimental flag. Adds newline and carriage return \n\r at the end of each line (except the last). Terminals wrap around and don't need new lines, but if you want to copy-paste the text outside the terminal you may want them. The output would be a single long string otherwise. Uses more CPU. |
-l , --loop-playback |
Loop video/gif forever (default: do not loop - play once) |
Substitute tplay
with cargo run --release --
if you plan to run from source.
# Run it
tplay <media> [options]
# Example: local image
tplay ./image.png
# Example: local gif
tplay ./image.gif
# Example: local video
tplay ./video.mp4
# Example: remote video (YouTube)
tplay https://www.youtube.com/watch?v=dQw4w9WgXcQ
# Example: remote video (Other)
tplay https://media.developer.dolby.com/Atmos/MP4/shattered-3Mb.mp4
# Example: YouTube video, with different char maps
tplay https://www.youtube.com/watch?v=fShlVhCfHig --char-map " ░▒▓█"
# Example: YouTube video, with different char maps (use w-mod to adjust width when using emoji-based char maps)
tplay https://www.youtube.com/watch?v=FtutLA63Cp8 --char-map "🍎🍏❤️😊" --w-mod 2
# Example: webcam on Linux (YMMV on other OSes)
tplay /dev/video0
0-9
- change character map (with0 0space
- toggle pause/unpauseg
- toggle grayscale/colorm
- toggle mute/unmuteq
- quit-a
/ --allow-frame-skip
flag.This is my ASCII media player: there are many like it, but this one is mine.
For other ASCII media players, check out: https://github.com/search?q=ascii+player&type=repositories
Contributions are welcome! Please open an issue or submit a pull request. Some ideas:
This project is licensed under the MIT License - see the LICENSE file for details.
Your Scientists Were So Preoccupied With Whether Or Not They Could, They Didn’t Stop To Think If They Should
Mostly did it for fun while learning Rust. I also wanted to see if it was possible to make a video player that could run in the terminal. I think it's pretty cool that you can play videos in the terminal now. I hope you enjoy it too!
Thanks to the following people for their contributions and support: