π¬ PlayCLI β Terminal Video Player
Real-time video playback in your terminal using ANSI true-color escape sequences, with 5 render modes, audio sync, subtitles, and adaptive quality.
π― What It Does
PlayCLI is a real-time terminal video player. It renders videos frame-by-frame directly in your terminal using 24-bit true color ANSI escape sequences β no GUI, no browser, just your shell.
$ playcli video.mp4
It supports 5 render modes, audio sync via your systemβs audio device, keyboard controls, subtitles, streaming from URLs, static images, playlists, screenshots (PNG + ANSI HTML), and adaptive quality throttling.
π§± Tech Stack
| Component | Technology |
|---|---|
| Language | Python 3.9+ |
| Video I/O | imageio-ffmpeg (FFmpeg via subprocess) |
| Math | NumPy (vectorized pixel ops) |
| Audio | sounddevice + soundfile (optional) |
| Images | Pillow (subtitle rendering, static images) |
| Fonts | Pillow + fontconfig (system font discovery) |
Zero external runtime dependencies beyond NumPy and imageio-ffmpeg for the core player. Audio and image extras are optional.
ποΈ Architecture
ascii_play/
βββ cli.py # Entry point, argparse dispatch
βββ player.py # FFmpeg decode loop, audio sync, keyboard input
βββ renderers.py # 5 render modes (MODES dict)
βββ resize.py # Quality levels: nearest, 4-tap, box filter
βββ ansi.py # ANSI escape sequence helpers
βββ subtitle.py # SRT parser + Pillow text overlay
The data flow:
cli.pyparses arguments and dispatches to the playerplayer.pyopens the video viaimageio-ffmpeg, reads frames as NumPy arrays, synchronizes to audio viasounddevice(or wall clock if no audio), captures keyboard events viatty.setraw(), and pushes rendered frames to stdoutrenderers.pyconverts each NumPy frame into ANSI escape codes using one of 5 modesresize.pydownsizes frames to fit terminal dimensions at configurable qualityansi.pyprovides the low-level ANSI sequences (cursor positioning, RGB color codes, clear screen)subtitle.pyparses SRT files and overlays text via Pillow before rendering
All pixel operations are NumPy-vectorized β no Python-level loops over pixels.
π¨ Render Modes
| Mode | Flag | Description |
|---|---|---|
| Half-block | --mode block (default) | Uses the β character with both foreground and background ANSI colors to double vertical resolution |
| ASCII art | --mode ascii | Maps luminance to ASCII characters (@%#*+=-:. ) |
| Braille | --mode braille | Uses braille dot patterns for high-density dithering |
| Dither | --mode dither | Floyd-Steinberg error diffusion dithering to 2-color |
| Edge | --mode edge | Sobel edge detection rendered as ASCII |
Half-block mode (β) is the star of the show. Each terminal cell renders one β character with a foreground color (top half) and background color (bottom half), effectively doubling the vertical resolution compared to a single colored character. This gives near-photographic quality in modern terminals that support 24-bit color.
π Audio Sync
PlayCLI uses sounddevice to play audio in a separate thread while the main thread renders video frames. The audio thread tracks the current playback position, and the video loop drops or repeats frames to stay in sync. If sounddevice is not installed, it falls back to wall-clock timing.
β¨οΈ Keyboard Controls
| Key | Action |
|---|---|
Space | Play / Pause |
q / Esc | Quit |
β / l | Forward 5s |
β / h | Backward 5s |
β / k | Volume up |
β / j | Volume down |
m | Mute |
f | Toggle fullscreen (term) |
s | Screenshot (PNG + ANSI HTML) |
0-9 | Toggle render mode |
π¦ Key Features
- Adaptive quality: Automatically reduces quality when frame decode falls behind real-time
- Streaming: URL playback via
yt-dlpintegration - Playlists: JSON playlist format with shuffle
- Subtitles: SRT file rendering via Pillow with configurable font
- Screenshots: Captures both a PNG image and an ANSI-escape HTML file
- Static images: Display images directly (no video)
- Persistent config:
~/.config/playcli/config.json
π Quick Start
pip install playcli
playcli video.mp4
# Stream from YouTube
playcli https://youtu.be/dQw4w9WgXcQ
# Use ASCII mode
playcli video.mp4 --mode ascii
# Keyboard shortcuts shown at bottom of terminal
π‘ Why Itβs Interesting
PlayCLI is a showcase of whatβs possible with ANSI terminal escape sequences when you push them to their limit. The half-block rendering technique gives surprisingly good video quality using nothing more than stdout output. Itβs genuinely useful for quick video previews without leaving the terminal, watching tutorials in a split pane, or just impressing your friends at a meetup.