Skip to content

TuKDoan/video-ascii

Repository files navigation

A simple python package to play videos in a terminal using ASCII characters.

frames

Requirements

  • Python3
  • PortAudio (Only required for installation with audio support)
  • FFmpeg (Only required for installation with audio support)

Installation

Standard installation

pip3 install ascii-video

With audio support installation

pip3 install ascii-video --install-option="--with-audio"

How to use

Just run ascii-video in your terminal

$ cd ../filepath/
$ ascii-video -f myvideo.mp4

Options

--strategy Allow to choose an strategy to render the output

$ ascii-video -f myvideo.mp4 --strategy filled-ascii
$ ascii-video -f myvideo.mp4--strategy ascii-color
$ ascii-video -f myvideo.mp4 --strategy just-ascii

-o --output Export the rendering output to a bash file to share with someone

$ ascii-video -f myvideo.mp4 -o myvideo-bash.sh

-a --with-audio If an installation with audio support was made, you can use this option to play the audio track while rendering the video ascii characters.

How it works

Every video is composed by a set of frames that are played at a certain frame rate.

frames

Since a terminal has a specific number of rows and columns, we have to resize our video to adjust to the terminal size limitations.

frames

To reach a correct visualization of an entire frame we need to adjust the frame height to match the terminal rows, avoiding using more characters than the number of terminal columns.

frames

When picking a character to represent a pixel we need to measure the relevance of that pixel's color in the frame, based on that we can then select the most appropriate character based on the relative luminance in colorimetric spaces, using a simplify version of the luminosity function.

LuminosityFunction

Green light contributes the most to the intensity perceived by humans, and blue light the least.

This function returns an integer in the range from 0 to 255, we assign a character according to density to show more colored surface for areas with more intense color (highest values).

CHARS_LIGHT 	= [' ', ' ', '.', ':', '!', '+', '*', 'e', '$', '@', '8']
CHARS_COLOR 	= ['.', '*', 'e', 's', '@']
CHARS_FILLED    = ['░', '▒', '▓', '█']

The reduced range of colors supported by the terminal is a problem we need to account for. Modern terminals support up to 256 colors, so we need to find the closest 8 bit color that matches the original pixel in 16 or 24 bit color, we call this set of 256 colors ANSI colors.

frames

colors

Finally, when putting it all together, we will have an appropriate character for each pixel and a new color.

frames

License

MIT © 2019 TuKDoan

About

Convert your videos into ASCII

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages