Terminal Video Player
Plays a video file or a YouTube video in the terminal as ASCII characters.
What it does
It plays a video in the terminal, drawn with ASCII characters. The source can be a local file (mp4, mkv, mov) or a YouTube link. For YouTube videos, it can also show the captions at the bottom of the screen.
This is one of my first projects on GitHub. It has 20 stars. talwat contributed code and ideas.
How it works
- OpenCV splits the video into frames and saves each frame as a JPEG.
- Pillow converts each frame to grayscale and resizes it to the size of the terminal.
- For each pixel, the brightness selects one of 11 characters. Curses draws the character at that position.
The character ramp goes from dark to light:
chars = ["B", "S", "#", "&", "@", "$", "%", "*", "!", ".", " "]
character = chars[int(int(pixel) // 25)]
For captions, the frame number divided by the frame rate gives the time. The player shows the caption that belongs to that time.
What I would change
I was 14.- The player calls
refresh()after each character, not after each frame. This makes the playback slow. - It writes every frame to disk twice, first the original and then the resized copy.
- There is no timing between frames. The playback speed depends on how fast the terminal draws.