This Python script converts a regular video file into ASCII art and plays it back in the terminal. It processes each frame of the video by converting it to grayscale, resizes it, and maps each pixel to an ASCII character based on its brightness.
- Python 3.x
- OpenCV (
cv2) - Pillow (
PIL) - curses
- Clone this repository or download the script.
- Install the required dependencies:
Note:
pip install opencv-python Pillowcursesis typically included in Python standard library on Unix-based systems. For Windows, ew, you may need to installwindows-curses.
Run the script with the path to your video file as an argument:
python3 main.py path/to/your/video.mp4
- Video to Frames: The script extracts individual frames from the video.
- Resize: Each frame is resized to fit the terminal window.
- Greyscale Conversion: Frames are converted to grayscale.
- ASCII Mapping: Each pixel is mapped to an ASCII character based on its brightness.
- Playback: The ASCII frames are displayed in the terminal in rapid succession.
The script uses the following mapping for converting brightness to ASCII characters:
- 0-31: ' ' (space)
- 32-63: '.'
- 64-95: ':'
- 96-127: '-'
- 128-159: '+'
- 160-191: '='
- 192-223: '%'
- 224-255: '@'
You can adjust the following parameters in the script:
- Frame rate (in
play_videofunction) - Output resolution (in
resize_imagesfunction) - ASCII character mapping (in
greyscale_to_asciifunction)
demonstration.mov
Feel free to fork this project and submit pull requests with improvements or bug fixes.