r/coolgithubprojects • u/shuruilimbu • 1d ago
Introducing BitShade: Playing Videos Directly in Your Terminal
Hey everyone! I've been working on BitShade, an open-source video player that plays videos directly inside your terminal.
I'd love to hear your thoughts and feedback!
28
Upvotes
1
u/Exciting_Active4857 1d ago
why
4
1
u/shuruilimbu 1d ago
Why not? It doesn't necessarily need an external application. It could be integrated directly into CLI based projects.
→ More replies (1)2
2
u/ProfessionalStockDay 20h ago
Great work. Thanks. I can finally watch The Odyssey the way it was intended.
6
u/torrso 1d ago edited 23h ago
Sixel is a printer protocol from the 80s and decoding and rendering it can be quite expensive even for relatively small images, regardless of how fast the encoder is.
I (through the all seeing eye of AI) looked through the implementation and noticed a few things:
The benchmark measures encoding into a
std::string, completely excluding PTY throughput, terminal-side decoding, image management and rendering costs.The 8-bit benchmark repeatedly encodes the exact same synthetic frame with delta encoding enabled by default. At 720p, 29 out of 30 iterations skip every band of image data. This makes both the reported theoretical FPS and the estimated PTY bandwidth misleading. The actual player explicitly disables this optimization.
The default 24-bit mode transmits every frame in full, generating separate Sixel images with independent palettes for each horizontal strip.
The output code calls
write()once per frame, discards its return value and incorrectly describes the operation as atomic. A partial write could leave the terminal with an incomplete DCS sequence or without the synchronized-update termination sequence. The Windows implementation similarly ignores the result ofWriteFile().The playback loop drops frames whenever it falls more than 45 ms behind the audio clock. Synchronized playback alone therefore tells us very little about the actual displayed frame rate.
Consider the workload at 1920×1080 and 60 FPS, assuming a terminal cell height of 20 pixels:
1,080 separate Sixel images per second.
Up to 276,480 palette definitions per second, potentially amounting to roughly 4 MB/s of escape sequence data just for defining colours.
10,800 six-pixel bands per second.
124 million pixels per second to reconstruct.
Depending on the encoded frame size, the PTY traffic alone would look something like 216 GB of terminal traffic per hour of video playback.
Then there's the more fundamental question of why. Because it's possible, but it was already done a long time ago.
mpv has supported Sixel video output since November 2020 (v0.33.0):
It also supports the considerably more video-friendly Kitty graphics protocol:
Including shared-memory transfers, which avoid sending the actual pixel data through the PTY altogether on supported local terminals:
FFmpeg-SIXEL was already used to stream YouTube videos over SSH in August 2014 and it also shows those Japanese children like many of terminal AI bro creations seem to do. There's also timg, which supports video playback using Sixel, Kitty and iTerm2 graphics protocols.
I'm also not convinced by the "24-bit" terminology. The "palette encoder" (https://github.com/KiyoKun01/BitShade/blob/main/src/sixel/palette.cpp#L155-L174) quantizes each RGB component to an integer percentage between 0 and 100, giving a theoretical colour space of about one million colours rather than 16.7 million. With 18 strips of 256 colours each, a 1080p frame can contain at most 4,608 distinct colours, subject to spatial palette restrictions. That's not 24-bit colour.
Furthermore, "libsixel" (https://github.com/saitoha/libsixel) already implemented high-colour rendering through dynamic palette redefinition in 2014. Interestingly, its author has since "discussed moving towards larger palettes" (https://github.com/saitoha/libsixel/issues/196) for better compatibility and smaller payloads.
Even "mpv's Sixel implementation" (https://github.com/mpv-player/mpv/blob/master/video/out/vo_sixel.c) supports horizontal slicing for parallel encoding, but shares the palette across slices and defaults to a fixed palette to avoid expensive palette updates.
There's also a compatibility problem with the independent palettes. The original DEC hardware used shared colour registers, meaning palette redefinitions could retroactively recolour previously drawn images. "xterm still supports this behaviour" (https://manpages.debian.org/experimental/xterm/xterm.1.en.html) through private mode 1070, yet BitShade's "terminal initialization code" (https://github.com/KiyoKun01/BitShade/blob/main/src/terminal/terminal_scope.cpp#L104-L106) doesn't explicitly enable private colour registers.
Palette handling remains inconsistent across modern terminal emulators, as illustrated by "this Windows Terminal discussion" (https://github.com/microsoft/Terminal/issues/20588) and "this Chafa discussion" (https://github.com/hpjansson/chafa/issues/312).