Asciline – 实时 ASCII 视频渲染引擎
Asciline – real-time ASCII video rendering engine

原始链接: https://github.com/YusufB5/ASCILINE

ASCILINE 是一款高性能、跨平台的引擎,能将实时视频渲染为交互式的排版 ASCII 字符或像素化 HTML/Canvas 流。它摒弃了传统的媒体编解码器,转而采用轻量级二进制协议,从而实现了不受浏览器自动播放限制和广告拦截器影响的动态网页视觉效果。 **核心特性包括:** * **高性能与高效率:** 利用自适应二进制编解码器(Raw、Zlib 或 Delta 压缩),大幅降低带宽占用,非常适合物联网(IoT)及低延迟环境。 * **AI 集成:** 将复杂视频转换为结构化的语义字符串,使轻量级大语言模型(LLM)无需复杂的计算机视觉处理即可解析视觉数据。 * **高度可定制:** 支持 1600 万色保真度、实时 CSS 操作以及基于 JSON 的播放列表。用户可通过 WebSocket 将流传输至浏览器,或直接传输至支持 ANSI 的终端。 * **前后端架构:** 后端由 Python/FastAPI(结合 OpenCV/NumPy)驱动,前端采用高性能原生 JavaScript 构建。 ASCILINE 在原始数据与创意网页画布之间架起了一座独特的高性能桥梁。注:本项目采用 MIT 许可证,明确禁止将此技术用于无法拦截的广告。 访问 **asciline.dev** 探索实时演示。

Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Asciline – 实时 ASCII 视频渲染引擎 (github.com/yusufb5) 16 分,发布者:godot,1 小时前 | 隐藏 | 过往 | 收藏 | 2 条评论 帮助 amarant 6 分钟前 | 下一条 [–] 我觉得这在技术上只能算是 ASCII 渲染。据我观察,渲染出来的字符始终是一样的,只是改变了颜色标签。这似乎是在优化易用性与复杂度之比,但却完全牺牲了“酷炫”感。但这毕竟是一个 ASCII 视频生成器,我本以为“酷炫”才是重点?我想不出它有什么实际用途…… 回复 xstas1 0 分钟前 | 父级 | 下一条 [–] 当然是在终端窗口里看视频了 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 加入 YC | 联系 搜索:
相关文章

原文

ASCILINE is a high-performance, cross-platform real-time ASCII video rendering engine. Our core objective is to transform the web into a highly dynamic and interactive typographic canvas. By mapping pixels to text-based representations, we unlock new possibilities for web media delivery.

🎯 Strategic Vision & Core Capabilities

  1. Pure Typographic Manipulation: The visual stream is not a standard media file—it's raw HTML/Canvas text. This makes the impossible possible: you can apply real-time CSS filters (neon glows, text shadows, animations) to video content.
  2. Local AI & LLM Ready: By reducing complex pixel streams into structured logical strings, ASCILINE acts as a perfect bridge for AI. Instead of feeding heavy computer vision models, lightweight LLMs can process semantic video summaries.
  3. Ultra-Low Bandwidth & IoT Compatibility (valid for ASCII MOD): Standard codecs (H.264/VP9) choke microcontrollers and weak networks. ASCILINE processes the heavy lifting once on the backend, streaming only a few kilobytes per frame.
  4. Bypassing Browser Constraints: Modern browsers aggressively throttle autoplay videos, and ad-blockers restrict traditional media frames. To the browser, ASCILINE is simply "JavaScript updating a canvas"—completely invisible to media restrictions.
  • Cross-Platform: Runs seamlessly on Windows, macOS, and Linux.
  • Real-Time ASCII Streaming: Low-latency video-to-ASCII conversion.
  • Real-Time Pixel Streaming: Replaces characters with colored blocks, approaching 360p video quality.
  • High Performance: Uses HTML5 Canvas for rendering, optimized for cinematic 24-30 FPS playback. High-FPS sources are automatically decimated for stability.
  • Master Clock Sync: The audio track acts as the absolute master clock, guaranteeing perfect A/V synchronization.
  • *Low-Overhead Binary Protocol: Frames are streamed as raw binary (Uint8Array) directly to the canvas, saving bandwidth and CPU.
  • Multiple Color Modes: Supports everything from classic B&W to 16M color ultra-fidelity.
  • Flexible Video Management: Supports JSON playlists (per-video mode & volume), folder-based auto-queuing (filesystem order), single-file mode, and infinite loop playback — all controlled via CLI arguments.
  1. Backend (Python/FastAPI): Decodes video using OpenCV, maps pixels to ASCII characters via NumPy, and streams binary data.
  2. Frontend (Vanilla JS): Receives binary frames via WebSockets, manages a jitter buffer, and renders to a Canvas grid.
  3. Communication: Optimized WebSocket protocol with a custom INIT handshake for dynamic resolution/FPS adjustment.

🗜️ Adaptive Frame Codec (opt-in, backward compatible)

The original binary protocol re-sends the full grid every frame. An opt-in adaptive codec picks the smallest of three encodings per frame and tags it in a 1-byte header — without changing the rendered output:

tag encoding best for
0 RAW framebuffer as-is (legacy) incompressible frames
1 ZLIB zlib(framebuffer) general motion
2 DELTA only the cells that changed since the last frame static / low-motion

Clients opt in with /ws?codec=adaptive; omit it and you get the original protocol byte-for-byte, so existing clients are unaffected. A keyframe is forced periodically so dropped packets / late joiners resync. The decoder (codec.js) is shared by the browser and the test suite, so the shipped path is the tested one.

Measured wire savings (mode 5, 200×80 grid):

content vs. legacy
static screen / slideshow 0.3% (≈375×)
pixel mode 11.6% (≈8.6×)
high-motion / full-frame change 63% (never worse than legacy)

An optional --quality {lossless,high,balanced,low} enables lossy temporal delta: a colour cell is only re-sent once it drifts past a tolerance from what the viewer already sees (the character plane stays exact), cutting the hard cases a further ~15–30% at imperceptible quality. Default is lossless (bit-exact).

Monitor Bandwidth in Real-Time: You can append the --debug flag when launching the server to see live bandwidth comparisons (RAW vs WIRE bytes) and the exact compression ratio in your terminal. This is highly useful for measuring the real-time savings of the adaptive codec on your specific video sources.

Verified two independent ways, both bit-exact: Python-encoded vectors decoded by codec.js in Node (experiments/gen_vectors.pyexperiments/check_vectors.js), and a live adaptive-vs-legacy WebSocket diff (experiments/test_e2e.js). Generate the test clips with experiments/make_test_clips.sh. (A fuller mutation-test + Autobahn

LAN / Network Streaming: To stream the video on your local network (Wi-Fi), use the --host flag:

python stream_server.py video.mp4 --host 0.0.0.0

git clone https://github.com/YusufB5/ASCILINE.git
cd ASCILINE
pip install fastapi uvicorn opencv-python numpy websockets

🔈 Audio Support (FFmpeg Required)

To enable server-side audio processing (Volume 1-5), you must have FFmpeg installed.

Option 1: Package Manager (Recommended)

  • Windows: winget install ffmpeg
  • macOS: brew install ffmpeg
  • Linux: sudo apt install ffmpeg

Option 2: Manual Installation (Windows) If you get a FileNotFoundError or don't want to modify system variables:

  1. Download FFmpeg ZIP.
  2. Extract ffmpeg.exe from the bin folder.
  3. Drop it directly into your ASCILINE project folder alongside stream_server.py.

Single video:

python stream_server.py video.mp4 --cols 240

Folder mode — drop your videos into videos/ and run:

python stream_server.py --folder videos --cols 200
python stream_server.py --folder videos --cols 230 --loop          # infinite loop
python stream_server.py --folder videos --mode 5 --pixel --cols 320 --vol 2  # all videos same settings

Videos play in filesystem order (top to bottom as they appear in the folder, not alphabetically). Just add/remove files from the videos/ folder to control the queue.

JSON Playlist — full control per video:

python stream_server.py --playlist playlist.json --cols 220
python stream_server.py --playlist playlist.json --cols 220 --loop

Use playlist.json when you need different --mode or --vol settings for each video.

💡 Windows Users: You can use the included serve.bat shortcut for quicker typing: .\serve video.mp4 --cols 240

Open http://localhost:8000 in your browser.

4. Run directly in Terminal (Standalone)

If you prefer to bypass the web interface, you can render the video directly inside an ANSI-supported terminal (zero-flicker, true color):

python ascii_video_player2.py video.mp4 --cols 100 --quality 0

💡 Windows Users: Use the shortcut .\play video.mp4 -c 100 -q 0

⚠️ Note: Do not resize your terminal window during playback, as dynamic text wrapping will corrupt the ASCII layout.

You can easily customize the look and feel of the engine:

Edit style.css to change the accent colors and typography using CSS variables:

:root {
    --accent-color: #00ff41; /* Classic Matrix Green */
    --bg-color: #050505;
}

The engine supports different fidelity levels via the --mode flag:

  • 1: Black & White (DOM mode)
  • 2: 512 Colors
  • 3: 32K Colors
  • 4: 262K Colors
  • 5: 16M Colors (Ultra)
python stream_server.py --mode 5 --cols 240 --rows 100

📐 Resolution & Auto-Scaling

By default, you only need to specify the width (--cols). ASCILINE will automatically calculate the correct --rows based on the source video's aspect ratio to prevent stretching.

  • ASCII Mode Recommended: --cols 200 to --cols 240 (Best balance of text detail and cinematic 30 FPS performance).
  • Pixel Mode Recommended: --cols 600 to --cols 900 (Provides near-HD visual quality. Performance heavily depends on your machine's CPU/VRAM).
  • Smart Defaults: If you do not specify a --cols value, ASCILINE automatically defaults to 450 when Pixel Mode is enabled, and 200 for standard ASCII text mode.

  • ⚠️ Hardware Limits & A/V Sync: If you push the --cols too high for your specific hardware (e.g., 1350 on a laptop vs a gaming desktop), the Python backend won't be able to encode and send the massive frames fast enough. When the video stream lags behind the audio, you will experience A/V desync (audio finishing early). If this happens, simply lower your --cols value!

python stream_server.py video.mp4 --mode 5 --cols 240
# Terminal will show: [AUTO] 1920x1080 → grid 240x67

Server-Side Volume Control

Volume is controlled at the server level via the --vol flag (scale 0–5). When set to 0, the audio engine (FFmpeg) never runs, saving CPU and bandwidth.

--vol FFmpeg Multiplier Description
0 Muted (no processing)
1 1.0× Normal (default)
3 1.5× Loud
5 2.0× Double volume
python stream_server.py video.mp4 --pixel --cols 560 --vol 0   # Silent
python stream_server.py video.mp4 --cols 220 --vol 3   # Loud

Playlist Format (playlist.json)

Each entry can override the global --mode, --pixel, --vol, and --cols defaults:

[
    { "video": "intro.mp4",  "mode": 1, "vol": 1 },
    { "video": "main.mp4",   "mode": 5, "pixel": true, "vol": 3, "cols": 520 },
    { "video": "outro.mp4",  "mode": 3, "vol": 2, "cols": 240 }
]

Video paths are resolved automatically — the engine checks the project root and the videos/ subfolder, so you can write just the filename.

ASCILINE is distributed under the MIT License, but with a strict ethical guardrail. Because this engine bypasses standard browser constraints and ad-blockers (by rendering pure text instead of video), we strictly prohibit its use by ad-networks to serve unblockable advertisements.

See the LICENSE file for the full text, which includes the ANTI-ADVERTISEMENT RESTRICTION clause.

🟢 Live Interactive Showcase

Experience the ASCILINE engine running live directly in your browser with multiple rendering modes. 👉 Try it out at asciline.dev

Star History Chart

☕ Support the Project ❤️

If you find this project helpful, you can support me by donating crypto:

  • Solana (SOL / USDC): H1wSQAhjgsu7AxenF4e5ZBYiBjkhDLVzkKaZuVPcrE14
  • Ethereum (ETH / USDT): 0x85B2f970045c0F7c282089Ab6CF897C20230e086
  • Bitcoin (BTC): bc1qvtcl55v54gkzwnp2zxn70usea3gf5ncncqa0fv

📜 License & Ethical Guardrails

MIT License (with Anti-Ad Restriction)

[email protected]

联系我们 contact @ memedata.com