It is a simple python package to play videos in the terminal using characters as pixels

Overview

Logo

It's a simple python package to play videos in a terminal using ASCII characters.

Financial Contributors on Open Collective PyPI version Maintainability contributions welcome HitCount

Screenshot

Translations

Requirements

  • Python3
  • PortAudio (Only required for installation with audio support)
  • FFmpeg (Only required for installation with audio support)
  • Linux or MacOS ... by now

Installation

Standard installation

$ pip3 install video-to-ascii

With audio support installation

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

How to use

Just run video-to-ascii in your terminal

$ video-to-ascii -f myvideo.mp4

Options

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

Render Strategies

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

Exporting

-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.

Video 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.

Terminal

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.

Resizing

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.

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.

The Mapping of RGB and ANSI Colors

8 Bits Color Table

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

Frame Image by Characters

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute].

Or maybe just buy me a coffee.

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

Comments
  • Non-ASCII character '\xf0'

    Non-ASCII character '\xf0'

    File "/usr/local/bin/video-to-ascii", line 8 SyntaxError: Non-ASCII character '\xf0' in file /usr/local/bin/video-to-ascii on line 8, but no encoding declared;

    bug solved 
    opened by msongz 15
  • Not Installable

    Not Installable

    pip3 install ./video-to-ascii Processing ./video-to-ascii Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-req-build-irufanr_/setup.py", line 17, in <module> install_package('opencv-python') File "/tmp/pip-req-build-irufanr_/setup.py", line 10, in install_package main.main(['install', package]) AttributeError: 'function' object has no attribute 'main' I get the same thing using pip3 install video-to-ascii I think there is an error in the code.

    bug 
    opened by ghost 9
  • time.clock() has been removed in Python3.8

    time.clock() has been removed in Python3.8

    Hi, I run this program to watch some video on macOS. But I encounter problem: AttributeError: module 'time' has no attribute 'clock'.

    After I search that, I know: time.clock() has been removed in Python3.8.

    I have checked the related line of file, and replace it with time.process_time(). Then it works well. Maybe need to use other API on other OS. https://github.com/joelibaceta/video-to-ascii/blob/5c812d5e7fd9466050dcdd6d4441ce077f2378d8/video_to_ascii/render_strategy/ascii_strategy.py#L120

    opened by YigaoFan 5
  • ZeroDivisionError

    ZeroDivisionError

    How to solve this Problem? i used pip not pip3 to install opencv-python and video-to-ascii because it is not work

    Traceback (most recent call last): File "/home/andre/anaconda3/bin/video-to-ascii", line 10, in sys.exit(main()) File "/home/andre/anaconda3/lib/python3.7/site-packages/video_to_ascii/cli.py", line 21, in main player.play(ARGS.file, strategy=ARGS.strategy, output=ARGS.output, play_audio=ARGS.with_audio) File "/home/andre/anaconda3/lib/python3.7/site-packages/video_to_ascii/player.py", line 23, in play engine.play(output) File "/home/andre/anaconda3/lib/python3.7/site-packages/video_to_ascii/video_engine.py", line 38, in play with_audio=self.with_audio) File "/home/andre/anaconda3/lib/python3.7/site-packages/video_to_ascii/render_strategy/ascii_strategy.py", line 113, in render time_delta = 1./fps ZeroDivisionError: float division by zero

    bug 
    opened by AndreLYL 5
  • Errors with included executable file

    Errors with included executable file

    Installing on macos Mojave using the system pip and python yields the following error on execution:

    ❯ video-to-ascii
    /usr/local/bin/video-to-ascii: line 3: import: command not found
    from: can't read /var/mail/video_to_ascii
    /usr/local/bin/video-to-ascii: line 6: syntax error near unexpected token `('
    /usr/local/bin/video-to-ascii: line 6: `CLI_DESC = ("It is a simple python package to play videos in the terminal"'
    

    On a closer look, it's because the file bin/video-to-ascii is missing the ! from the shebang line, which should read like so:

    #!/usr/bin/env python
    

    Furthermore, you'll also want to include a line like this:

    # coding=utf-8
    

    Otherwise, I get this error:

    258 ❯ video-to-ascii
      File "/usr/local/lib/python2.7/bin/video-to-ascii", line 9
    SyntaxError: Non-ASCII character '\xf0' in file /usr/local/lib/python2.7/bin/video-to-ascii on line 9, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
    
    bug solved 
    opened by tomplex 4
  •     error: option --with-audio not recognized

    error: option --with-audio not recognized

    D:>pip3 install video-to-ascii --install-option="--with-audio" c:\users\footb\appdata\local\programs\python\python38\lib\site-packages\pip_internal\commands\install.py:230: UserWarning: Disabling all use of wheels due to the use of --build-option / --global-option / --install-option. cmdoptions.check_install_build_global(options) Collecting video-to-ascii Using cached video_to_ascii-1.2.9.tar.gz (6.1 kB) Collecting xtermcolor Using cached xtermcolor-1.3.tar.gz (3.8 kB) Collecting ffmpeg-python Using cached ffmpeg-python-0.2.0.tar.gz (21 kB) Collecting future Using cached future-0.18.2.tar.gz (829 kB) Skipping wheel build for video-to-ascii, due to binaries being disabled for it. Skipping wheel build for ffmpeg-python, due to binaries being disabled for it. Skipping wheel build for future, due to binaries being disabled for it. Skipping wheel build for xtermcolor, due to binaries being disabled for it. Installing collected packages: future, xtermcolor, ffmpeg-python, video-to-ascii Running setup.py install for future ... error ERROR: Command errored out with exit status 1: command: 'c:\users\footb\appdata\local\programs\python\python38\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\footb\AppData\Local\Temp\pip-install-t_3_1qvw\future_95a3c7a8272d4d5ebfe5d44600f86280\setup.py'"'"'; file='"'"'C:\Users\footb\AppData\Local\Temp\pip-install-t_3_1qvw\future_95a3c7a8272d4d5ebfe5d44600f86280\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\footb\AppData\Local\Temp\pip-record-cg0z8f53\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\footb\appdata\local\programs\python\python38\Include\future' --with-audio cwd: C:\Users\footb\AppData\Local\Temp\pip-install-t_3_1qvw\future_95a3c7a8272d4d5ebfe5d44600f86280
    Complete output (6 lines): usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help

    error: option --with-audio not recognized
    ----------------------------------------
    

    ERROR: Command errored out with exit status 1: 'c:\users\footb\appdata\local\programs\python\python38\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\footb\AppData\Local\Temp\pip-install-t_3_1qvw\future_95a3c7a8272d4d5ebfe5d44600f86280\setup.py'"'"'; file='"'"'C:\Users\footb\AppData\Local\Temp\pip-install-t_3_1qvw\future_95a3c7a8272d4d5ebfe5d44600f86280\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\footb\AppData\Local\Temp\pip-record-cg0z8f53\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\footb\appdata\local\programs\python\python38\Include\future' --with-audio Check the logs for full command output.

    opened by HunterG6700 3
  • ValueError: not enough values to unpack (expected 2, got 0)

    ValueError: not enough values to unpack (expected 2, got 0)

    I've pip installed opencv-python and video-to-ascii in my PC, which runs Windows 10, Chinese simplified version. However, I constantly encouter the ValueError when I try to run "video-to-ascii -f filepath" command in terminal. Following is a screenshot about my commands. image How can I solve this trackback? Thanks.

    opened by Alowree 3
  • I cant install: No module named 'pip._internal'

    I cant install: No module named 'pip._internal'

    pip3 install video-to-ascii --install-option="--with-audio" /usr/lib/python3/dist-packages/pip/commands/install.py:212: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options. cmdoptions.check_install_build_global(options) Collecting video-to-ascii Downloading https://files.pythonhosted.org/packages/69/76/421fff0085dda88307ddb8bf31f4c99de815e707aaca28dae4a44330555f/video_to_ascii-1.2.6.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/tmp/pip-build-wb40_x50/video-to-ascii/setup.py", line 16, in install_package('opencv-python') File "/tmp/pip-build-wb40_x50/video-to-ascii/setup.py", line 8, in install_package from pip._internal import main as pip ModuleNotFoundError: No module named 'pip._internal'

    ----------------------------------------
    

    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-wb40_x50/video-to-ascii/

    opened by hectorprats 3
  • Fixed the typos and wrong links in the original README file and add translations in Traditional Chinese.

    Fixed the typos and wrong links in the original README file and add translations in Traditional Chinese.

    • Fixed the typos and wrong links in the original README file.
    • Add the translations section in each README file.
    • Move the README in different languages into the translations folder to keep the folder structure clear.
    hacktoberfest-accepted 
    opened by Hsins 2
  • Translate readme to main spoken languages

    Translate readme to main spoken languages

    Due to global reach of this project we need to translate our readme to main spoken languages as:

    • [x] spanish or
    • [x] chinese

    We suggest use the format readme_es.md for naming the translated file .

    hacktoberfest 
    opened by joelibaceta 2
  • Doesn't work python 3.8

    Doesn't work python 3.8

    I got 'AttributeError: module 'time' has no attribute 'clock''. A simple google search let me to believe the 'time.clock()' function has been removed and replace by another. https://stackoverflow.com/questions/58569361/attributeerror-module-time-has-no-attribute-clock-in-python-3-8

    opened by MatisseBE 2
  • Pyaudio replaced by sounddevice library to fix some errors

    Pyaudio replaced by sounddevice library to fix some errors

    Currently, the Pyaudio library is getting errors when executed by Python 3.10. Changing the library to sounddevice fix this and get a robuster way to work with the audio stream.

    opened by RadinhoDePilha 0
  • Cannot Use Audio

    Cannot Use Audio

    After Installing the package, When i want to see a video with audio (-a) it gives the error ModuleNotFoundError: No module named 'pyaudio'

    I installed the package:

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

    Used it :

    video-to-ascii -f rickroll.mp4 --strategy filled-ascii -a
    

    It gives error. I also ran it with no audio and it worked Screenshots Screenshot from 2022-06-22 13-37-03 Screenshot from 2022-06-22 13-37-06

    • OS: Ubuntu 20.04
    • Python version: 3.8
    opened by mehanalavimajd 1
  • Error: ALSA lib pcm.c:8545:(snd_pcm_recover) underrun occurred

    Error: ALSA lib pcm.c:8545:(snd_pcm_recover) underrun occurred

    Hello! "ALSA lib pcm.c:8545:(snd_pcm_recover) underrun occurred" error. It plays, but the sound is very laggy. Tried restarting pulseaudio but didn't help. I tried "aconnect -x", the sound became a little better (faster), but the same error also lags. The error occurs at the bottom of the video. Collected using a script, with audio support. Debian, bullseye.

    opened by Fexonchik5120 0
  • Fixed setup.py

    Fixed setup.py

    I was unable to install the package. I found that the setup.py has a mistake in it.

    I fixed it here, please approve this request at : https://github.com/joelibaceta/video-to-ascii/pull/80

    opened by D4RKH0R1Z0N 0
Releases(1.2.9)
Owner
Joel Ibaceta
Software Engineer, Fintech Expert, Technical Advisor, Digital Nomad, Open Source Contributor, Investor
Joel Ibaceta
VIT - VideoInTerminal. A quick piece of code to play videos in your terminal using python

VIT VIT - VideoInTerminal. A quick piece of code to play videos in your terminal using python.

ShellTear 3 Mar 3, 2022
Stream-Cli application that allow you to play your favorite movies from the terminal

Stream-Cli application that allow you to play your favorite movies from the terminal

redouane 380 Jan 8, 2023
Program to play videos with props in Apex Legends

R5Fresh A video player for the Apex Legends mod R5Reloaded

null 9 Nov 13, 2022
Convert lecture videos to slides in one line. Takes an input of a directory containing your lecture videos and outputs a directory containing .PDF files containing the slides of each lecture.

Convert lecture videos to slides in one line. Takes an input of a directory containing your lecture videos and outputs a directory containing .PDF files containing the slides of each lecture.

Sidharth Anand 12 Sep 10, 2022
A simple Telegram bot to extract hard-coded subtitle from videos using FFmpeg & Tesseract.

Video Subtitle Extractor Bot A simple Telegram bot to extract hard-coded subtitle from videos using FFmpeg & Tesseract. Note that the accuracy of reco

null 14 Oct 28, 2022
TkVideoplayer - This is a simple library to play video files in tkinter.

TkVideoplayer - This is a simple library to play video files in tkinter.

Art/Paul 38 Dec 23, 2022
This plugin generates json files used by deovr allowing you to play 2d and 3d video's using the player

deovr-plugin This plugin generates json files used by deovr allowing you to play 2d and 3d video's using the player. Deovr looks for an index file /de

null 10 Sep 29, 2022
Play Video & Music on Telegram Group Video Chat

?? DEMONGIRL ?? ʜᴇʟʟᴏ ❤️ ???? Join us ᴠɪᴅᴇᴏ sᴛʀᴇᴀᴍ ɪs ᴀɴ ᴀᴅᴠᴀɴᴄᴇᴅ ᴛᴇʟᴇʀᴀᴍ ʙᴏᴛ ᴛʜᴀᴛ's ᴀʟʟᴏᴡ ʏᴏᴜ ᴛᴏ ᴘʟᴀʏ ᴠɪᴅᴇᴏ & ᴍᴜsɪᴄ ᴏɴ ᴛᴇʟᴇɢʀᴀᴍ ɢʀᴏᴜᴘ ᴠɪᴅᴇᴏ ᴄʜᴀᴛ ?? ɢ

Jonathan 5 Dec 31, 2021
A web RTSP play platform based on websocket and tornado, websocket use blob binaryType read as ArrayBuffer

A web RTSP play platform based on websocket and tornado, websocket use blob binaryType read as ArrayBuffer

null 2 Feb 25, 2022
Python Script for Streaming YouTube Videos in VLC Media Player.

Short Description Use this Simple Script to stream YouTube Video to VLC

Sijey 6 May 27, 2021
A python generator that converts youtube videos to ascii art in your console.

Video To ASCII A python generator that converts youtube videos to ascii art in your console. This has not been tested for windows! Example Normal mode

Julian Jones 24 Nov 2, 2022
BlogBot - a Python script that create blogs from YouTube videos.

BlogBot - Convert Youtube Videos To Blogs BlogBot is a Python script that create blogs from YouTube videos.

Nikhil Bhamere 4 Apr 22, 2022
Python program - to extract slides from videos

Programa em Python - que fiz em algumas horas e que provavelmente tem bugs - para extrair slides de vídeos.

Natanael Antonioli 45 Nov 12, 2022
Python package to display video in GUI using OpenCV-Python and PySide6

Python package to display video in GUI using OpenCV-Python and PySide6. Introduction cv2PySide6 is a package which provides utility classes and functi

null 3 Jun 6, 2022
A Telegram bot to convert videos into x265/x264 format via ffmpeg.

Video Encoder Bot A Telegram bot to convert videos into x265/x264 format via ffmpeg. Configuration Add values in environment variables or add them in

Adnan Ahmad 82 Jan 3, 2023
pygamevideo module helps developer to embed videos into their Pygame display

pygamevideo module helps developer to embed videos into their Pygame display. Audio playback doesn't use pygame.mixer.

Kadir Aksoy 10 Dec 28, 2022
Playing videos through S3 buckets (Wasabi, AWS, etc.) through client-side VideoJS player

Playing videos through S3 buckets (Wasabi, AWS, etc.) through client-side VideoJS player without incurring ingress/egree traffic on EC2 Instance.

Syed Umar Arfeen 8 Mar 28, 2022
goal: render videos on eu4's timeline function

Rendering Videos on the EU4 Time Line This repository contains code to create an eu4-savefile that plays back a video in question.

null 29 Dec 24, 2022
Youtube as covert-channel - Control systems remotely and execute commands by uploading videos to Youtube

covert-tube A program to control systems remotely by uploading videos to Youtube using Python to create the videos and the listener, emulating some ma

Ricardo Ruiz 101 Nov 1, 2022