Bbabo NET

Science & Technology News

The developer introduced a more efficient video player for the terminal

Comparison of a frame from the video player with the Starship launch video and the iconic "telnet towel.blinkenlights.nl".

The developer under the nickname TheRealOrange published on GitHub the source code of his version of the tvp video player for the terminal, which effectively encodes from 4 to 11 pixels of the video stream at once usingle Unicode character. True, pixels are still not independent, and each unicode character is still limited to two colors when drawn. He also managed to optimize his solution to correctly change the color of the text or background on the video, even if several nearby pixels are quite similar.

The author posted the project under the open license GPL-3.0. The video player code for the terminal is written in C++ (440 lines).

The developer recommends using the alacritty version of the terminal emulator for tests, as tvp works with optimal performance there. In his project, the developer does not use FFmpeg for video decoding, but the OpenCV library.

The author of tvp explained that this is not a new development. But most of the terminal video players he's seen use a simple encoding of two pixels per unicode character. He also decided to use the full potential of the available unicode palette and use unicode quarter-block characters, as well as half-blocks and other available variations, to encode several pixels.

The developer was eventually able to achieve four times the effective resolution horizontally and twice the vertical resolution compared to encoding two pixels per unicode character. The tvp video player is limited to two colors per pixel. Its algorithm can be tailored to each video by manually tweaking the threshold [0-255] option (default is 10) which minimizes the maximum difference between colors to be made equal, and then sets their display color to medium. A lower value of the threshold option in most cases results in more redraws and results in a more choppy video.

An example of the video player for the terminal.

Users appreciated the idea of ​​the author. “Works well on kitty (terminal size 317x86, so 640p), plays animation very well. Tested on Ghost in the Shell, sometimes performance dropped to 20 fps when there is a lot going on in the video. Image quality is better than vlc in caca mode,” wrote a Reddit contributor to this project.

The developer introduced a more efficient video player for the terminal