This is a Python program that plays videos in ASCII character form in the terminal. It uses FFmpeg to extract video frames, converts them to grayscale images, and then maps each pixel to ASCII characters, creating an effect similar to character art.
- 🎬 Real-time playback of videos as ASCII art in the terminal
- ⚡ Fast frame processing with optimized algorithms
- 🖥️ Automatic adaptation to terminal size
- 📊 Displays playback status information (frame count, elapsed time, FPS)
- 🔧 Supports custom frame rates and resolutions
- Python 3.6+
- FFmpeg (required)
# Install Python dependencies
pip install -r requirements.txt
# Install FFmpeg (based on your operating system)
# Ubuntu/Debian
sudo apt install ffmpeg
# macOS
brew install ffmpeg
# Windows
# Download from https://ffmpeg.org/download.html and add to system PATH-
Clone or download the project files
-
Install Python dependencies:
pip install -r requirements.txt
-
Ensure FFmpeg is installed and accessible from the command line
go to the src directory:
cd srcChange the code at the end of the main.py file to:
if __name__ == "__main__":
main()# Basic usage
python main.py <video_file_path>
# Specify frame rate and width
python main.py <video_file_path> --fps 30 --width 100
# Example
python main.py "my_video.mp4" --fps 24 --width 120Modify the following parameters at the bottom of the main.py file:
if __name__ == "__main__":
video_path = r"your_video_file_path"
play_video_in_ascii(video_path, 30, 2000) # 30 FPS, max width 2000Then run python main.py to play the video in the terminal.
| Argument | Description | Default |
|---|---|---|
video_path |
Video file path (required) | - |
--fps |
Playback frame rate | 15 |
--width |
Maximum width of ASCII image | 80 |
- Video Processing: Uses FFmpeg to extract video frames, converts to grayscale, and resizes
- ASCII Conversion: Maps grayscale pixel values to a set of ASCII characters (dark to bright: @#*+=-:.)
- Terminal Rendering: Clears the terminal and displays the ASCII representation of the current frame
- Frame Rate Control: Controls playback speed by adjusting read and processing speed
- Uses precomputed character mapping table for faster conversion
- Uses faster image scaling algorithm (fast_bilinear)
- Directly processes grayscale images to avoid color conversion overhead
- Pre-allocates buffers to reduce memory allocation
-
"Error: FFmpeg not found"
- Ensure FFmpeg is correctly installed and added to the system PATH
-
ASCII image distorted or incorrect size
- Adjust the
--widthparameter or terminal size - Ensure the terminal supports ANSI escape codes
- Adjust the
-
Playback too slow
- Lower the
--fpsparameter value - Reduce the
--widthparameter value
- Lower the
- Press
Ctrl+Cto stop playback
In the convert_frame_to_ascii_fast function in main.py, you can modify the ascii_chars variable to customize the character set:
# Default character set (dark to bright)
ascii_chars = "@#*+=-:."
# Inverted character set (bright to dark)
# ascii_chars = " .:-=+*#@"
# More detailed character set
# ascii_chars = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "- Playback effect depends on terminal size and font size
- High-resolution videos may require more processing time
- Some terminals may not support ANSI escape codes, causing display issues
- Ensure the terminal has sufficient height to display the complete ASCII frame
This project is open source and intended for learning and research purposes only.
Pro tip: For best results, use a modern terminal that supports ANSI escape codes and adjust the terminal window size to match the video aspect ratio.