What is CurlCast?
CurlCast is a high-performance terminal multimedia engine designed to render photos, animated GIFs, and high-definition video directly inside your command line in crisp, 24-bit TrueColor terminal art — complete with hardware-synchronized audio playback.
Historically, terminal media rendering has been plagued by crude monochrome character ramps, sluggish frame rates, heavy screen tearing and flickering from full-screen clears, and a complete absence of audio synchronization. Playing video in terminal environments typically required heavy system-level dependencies, complex external configurations, or popped open separate GUI windows. CurlCast reimagines terminal multimedia as a self-contained, zero-system-dependency streaming pipeline. By coupling Unicode half-block pixel pairing (▀) with run-length-optimized ANSI escape caching, portable embedded FFmpeg decoding via imageio-ffmpeg, and an audio-master clock driven directly by PortAudio (sounddevice), CurlCast delivers fluid 30–60+ FPS terminal video playback that stays locked to audio without drifting.
Key Features
🔤 Adaptive Luminance ASCII Art Engine
- Translates media luminance onto an empirically balanced glyph density ramp.
- Features adaptive contrast stretching that dynamically clips scene luminance between the 1st and 99th percentiles, ensuring crisp detail in both low-key and high-key scenes.
- Implements exponential moving-average smoothing across consecutive video frames to prevent visual luminance "pumping" during scene transitions.
- Supports high-contrast artistic monochrome representation by default, with
--color for 24-bit RGB TrueColor.
🔊 Hardware-Synchronized, Drift-Corrected Audio Engine
- Treats the audio hardware stream as the authoritative master clock (
audio position = stream.time - baseline - latency).
- Video frame pacing is slaved to the active audio stream: absolute frame deadlines (
index / fps) prevent frame jitter from accumulating into audio-video drift.
- Automatically drops late frames (more than two intervals behind) if the terminal emulator experiences heavy rendering bottlenecks, preserving perfect lipsync and audio continuity.
- Multi-tier fallback architecture: automatically probes and routes through
sounddevice (PortAudio) → ffplay → mpv → afplay (macOS M4A bridge) → graceful silence with clear status logging.
⚡ Zero-Flicker Single-Buffer Display Engine
- Completely eliminates screen flicker and strobe artifacts by avoiding destructive terminal clears (
ESC[2J or cls).
- Repaints frames in-place using cursor-home repositioning (
ESC[H) combined with single atomic buffer writes and trailing line clearance (ESC[J).
- Safely manages terminal state: automatically hides the cursor on launch and guarantees cursor and virtual terminal restoration on normal exit or
Ctrl+C interrupt via robust finally teardown handlers.
📐 Sub-Pixel Geometry & Aspect Ratio Normalization
- Corrects for standard ~2:1 vertical character cell geometry.
- Enforces strict mathematical aspect ratio constraints: preserves exact aspect ratio across all zoom levels, including adaptive compensation for micro-font cell flattening.
- Fully verified against 16:9 widescreen, 4:3 standard, 1:1 square, 9:16 vertical mobile, and ultrawide media formats.
- Automatically handles EXIF orientation metadata for mobile smartphone photos and videos.
🎞️ Multi-Format Media Engine & Zero System Dependencies
- Ships with zero external system requirements — no pre-installed system
ffmpeg, gstreamer, or codec libraries needed. Portable FFmpeg binaries are automatically managed via imageio-ffmpeg.
- Full playback support for MP4, MKV, WebM, AVI, MOV, and animated GIFs.
- Dedicated GIF decoder engine via Pillow with full frame disposal method handling, localized per-frame delay timings, and alpha channel compositing.
🧩 Pluggable & Extensible Renderer Architecture
- Object-oriented strategy pattern based on
BaseRenderer.
- Developers can implement custom renderers (such as Braille patterns, custom shading palettes, or colored matrix glyphs) and register them into the CLI runtime with a single decorator or function call.
🌀 Self-Contained Generative Demos
- Ships with built-in, pure NumPy mathematical animation sources: a colorful multi-frequency plasma field and a 3D z-buffered spinning torus.
- Allows immediate verification of terminal color capabilities, geometry budgets, and playback frame rates with zero external media files.
Architecture & Media Pipeline
+-----------------------------------------------------------------------------+
| MEDIA SOURCE |
| (Video File: MP4/MKV/WebM, Animated GIF, or Image) |
+-------------------------------------+---------------------------------------+
|
v
+-----------------------------------------------------------------------------+
| PRE-FLIGHT PROBE & GEOMETRY |
| - Extract dimensions, duration, SAR/DAR, and rotation metadata |
| - Query terminal viewport dimensions (cols x rows) via kernel API |
| - Compute target bounding box enforcing 2:1 terminal cell correction |
+-------------------------------------+---------------------------------------+
|
+----------------+----------------+
| |
v v
+-----------------------------------+ +-------------------------------------+
| AUDIO SUB-PIPELINE | | VIDEO SUB-PIPELINE |
| - Extract audio stream via ffmpeg| | - ffmpeg hardware/CPU decode |
| - Initialize PortAudio stream | | - Target-scale via Lanczos filter |
| - Start hardware playback clock | | - Stream raw RGB24 into pipe |
+--------------------+--------------+ +------------------+------------------+
| |
| Audio Master Clock | Raw RGB Frames
| (stream.time - latency) | (bounded queue)
| |
+---------------->+<------------------+
|
v
+-----------------------------------------------------------------------------+
| PACING & DRIFT-CORRECTION LOOP |
| - Compute deadline: target_pts = index / target_fps |
| - Query delta against master audio position |
| - Drop frame if > 2 intervals behind; sleep if ahead of schedule |
+--------------------------------------+--------------------------------------+
|
v
+-----------------------------------------------------------------------------+
| ACTIVE RENDERER STRATEGY |
| [ASCII Mode: Glyph Density Engine] |
| - Adaptive contrast stretch |
| - Dynamic LUT glyph mapping & quantization |
| - In-place run-length ANSI escape emission |
+-----------------------------------------------------------------------------+
|
v
+-----------------------------------------------------------------------------+
| ZERO-FLICKER ATOMIC TERMINAL SINK |
| - ESC[H (Home Cursor) + Encoded Frame Buffer + ESC[J (Clear Remaining) |
| - Single atomic standard output write per frame |
+-----------------------------------------------------------------------------+
Directory Structure
src/curlcast/
├── __init__.py # Package version (__version__) and public metadata
├── __main__.py # python -m curlcast invocation entrypoint
├── cli.py # Typer CLI application (view, play, cam, screen, broadcast)
├── terminal.py # Win32/POSIX terminal setup, sizing, non-blocking keys, flicker-free Screen
├── ffmpeg.py # Bundled portable ffmpeg binary resolver & ffprobe parser
├── player.py # Media frame decoders, bounded queues, drift-corrected loop
├── audio.py # PortAudio (sounddevice) stream manager & fallback engines
├── lyrics.py # Timestamped .lrc/.srt subtitle parser & dynamic semantic glyph ramps
├── capture.py # Real-time webcam (ffmpeg/dshow/v4l2) and desktop screen grabber with split-region
├── server.py # AsyncIO HTTP chunked streaming server for vanilla curl clients
├── py.typed # PEP 561 static typing marker
└── renderers/
├── __init__.py # Renderer registry (register_renderer, get_renderer)
├── base.py # BaseRenderer abstract strategy & fit() geometry engine
├── effects.py # Retro CRT/Amber/Green/GameBoy/Synthwave shaders, Bayer/Floyd dithering, 3D
├── normal.py # 2.5D Sobel surface normal estimation & interactive flashlight
├── _pixels.py # High-performance NumPy color quantization & helpers
└── ascii.py # Adaptive contrast ASCII art renderer
Tech Stack
Core Engine & CLI:
- Python 3.10+ (Modern typed Python with strict static typing)
- Typer & Rich (Ergonomic CLI command routing, argument parsing, and styled console feedback)
Video & Media Processing:
- imageio-ffmpeg (Bundles portable, self-contained FFmpeg binaries with zero system installation)
- Pillow (PIL) (Image decoding, EXIF orientation correction, screen capture, and animated GIF frame extraction)
- NumPy (Vectorized RGB frame manipulation, contrast clipping, shaders, dithering, and surface normals)
Audio Engine & Synchronization:
- sounddevice & PortAudio (Low-latency asynchronous audio streaming and hardware-level master clock)
- ffplay / mpv / afplay (Resilient secondary and platform-native audio fallbacks)
Terminal Graphics & System Integration:
- ANSI 24-Bit TrueColor (Full RGB
38;2;r;g;b color gamut)
- Windows Virtual Terminal Processing (
kernel32 Win32 API bridge enabling UTF-8 and VT escape sequences on Windows consoles)
- Single-Buffer In-Place Repainting (
ESC[H cursor-home repaint eliminating full-screen clear flicker)
Testing & Quality Assurance:
- Pytest (Comprehensive test suite spanning aspect ratios, geometry, decoders, audio clocks, and CLI)
- Ruff (Blazing-fast linting and code formatting)
- Mypy (Strict type verification across all modules)
Quick Start Guide
Prerequisites
- Python ≥ 3.10
- A terminal with 24-bit TrueColor support:
- Windows: Windows Terminal (strongly recommended) or Windows 10+ standard console (
conhost.exe).
- macOS: iTerm2, Kitty, Ghostty, Alacritty, or Terminal.app.
- Linux / WSL2: GNOME Terminal, Konsole, Alacritty, Kitty, WezTerm, etc.
- An audio output device (optional; video playback automatically falls back to silence if no audio device is present).
Installation Options
Option A: Install from PyPI (Recommended)
pip install curlcast
Option B: Install from Source (Development / Editable)
# 1. Clone repository
git clone https://github.com/VutukuriEswar/CurlCast.git
cd CurlCast
# 2. Set up virtual environment
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On macOS / Linux:
# source .venv/bin/activate
# 3. Install in editable mode with development dependencies
pip install -e ".[dev]"
CLI Commands & Usage Reference
1. View Static Images (curlcast view)
Renders a still photo or graphic in the terminal and exits cleanly.
# Render image in default high-contrast artistic monochrome ASCII
curlcast view photo.jpg
# Render with 24-bit TrueColor enabled
curlcast view photo.jpg --color
# Constrain output width to 120 character columns
curlcast view photo.jpg --width 120
# Render with retro CRT monitor scanlines
curlcast view photo.jpg --color --shader crt
# Render with ordered 8x8 Bayer dithering
curlcast view photo.jpg --dither bayer
# Interactive 2.5D flashlight (steer with arrow keys)
curlcast view photo.jpg --flashlight
# Red-cyan stereoscopic 3D
curlcast view photo.jpg --3d
# Render once and exit immediately
curlcast view photo.jpg --once
| Option |
Flag |
Default |
Description |
--width |
-w |
0 (auto) |
Output width in columns (0 automatically fits terminal width). |
--color |
— |
False |
Enables 24-bit RGB TrueColor output (default: monochrome). |
--shader |
-s |
none |
Retro shader: crt, amber, green, gameboy, synthwave. |
--dither |
— |
none |
Dithering engine: bayer (8x8 matrix) or floyd (error diffusion). |
--3d |
— |
False |
Red-Cyan stereoscopic 3D mode. |
--flashlight |
— |
False |
Interactive 2.5D flashlight with dynamic surface normals. |
--text |
-t |
"" |
Custom phrase for typographic ASCII rendering. |
--no-upscale |
— |
False |
Prevents enlarging images smaller than the terminal viewport. |
--once |
-1 |
False |
Render once and exit without interactive viewer. |
2. Play Videos & GIFs (curlcast play)
Plays a video or animated GIF in real time with synchronized audio.
# Play video with synchronized audio (monochrome ASCII)
curlcast play movie.mp4
# Play video with full TrueColor enabled
curlcast play movie.mp4 --color
# Typographic video cinema (rendered using phrase, .srt, .lrc, or .txt file)
curlcast play song.mp4 --color --text song.srt
# Interactive 2.5D flashlight (steer with arrow keys)
curlcast play movie.mp4 --flashlight
# Retro synthwave shader with 8x8 Bayer dithering
curlcast play movie.mp4 --color --shader synthwave --dither bayer
# Broadcast video live over local network to curl clients
curlcast play movie.mp4 --serve 8080