A package which can convert videos, images, gifs, and even live video to ascii art!
Project description
To-Ascii
Converts videos, images, gifs, and even live video into ascii art!
- Works on most common image types
- Works on most common video types
- Works on LIVE VIDEO
- Works on gifs
How does it work?
Videos:
When the conversion process is started, the video file is opened up and went through frame by frame. Each frame is composed of a set of arrays like [[[r, g, b], [r, g, b]], [[r, g, b], [r, g, b]]]
, the software then goes through each frame and calculates the average brightness of each pixel, which is then used to get a value from a gradient of ascii characters. Then, at the end, a set of "pretty" frames are made, that list looks like ['frame', 'frame',..]
with frame obviously being the ascii art for each frame. When .view()
is called or the video is viewed, the software print()
s out each frame and then time.sleep()
s for a bit.
Images:
The process is virtually identical to the one above, except it doesn't need to do a multitude of frames/images, it only needs to convert one. When .view()
is called it just displays the image.
Installation
Via pip:
python3 -m pip install to-ascii
Example Usage
CLI:
to-ascii -t filetype -f filename
Video / GIF:
from toascii import Video
v = Video('my_file.mp4', scale=.1, verbose=True)
v.convert() # convert the frames into ascii
v.view() # play the converted frames in the console
Live Video:
from toascii import Live
l = Live(scale=.1, verbose=True)
l.view()
Image:
from toascii import Image
img = Image('my_image.png', scale=.1, verbose=True) # load the image
img.convert() # convert the image to ascii
img.view() # view the final asciified image
Documentation
- toascii.Video(filename='video.mp4', *, scale=1, w_stretch=2, gradient=Union[int, str], verbose=False)
- Note: only filename can be a positional argument, the rest are kwargs.
- Arguments:
filename: str
the name of the file/video which is to be opened and processedscale: float
the amount/1 which the video dimensions are multiplied byw_stretch: float
the amount that the width dimension is multiplied bygradient: Union[int, str]
either an integer from the preset gradients, or a custom gradient Example: '#$a=+-., 'verbose: boolean
whether or not to show extra information
- Functions:
convert()
actually converts the video into asciiview(fps: float)
view the converted video
- Attributes:
filename: str
the name of the file/video which was opened and processedvideo: cv2.VideoCapture
the actualcv2.VideoCapture
objectframes: list
the converted frames, will be populated when.convert()
is calledfps: float
the fps of the videowidth: int
the unaltered width of the videoheight: int
the unaltered height of the videoscale: float
the scale which is applied to both the dimensions of the videow_stretch: float
the scale which is only applied to the width dimensionscaled_width: int
the final scaled widthscaled_height: int
the final scaled heightgradient: tuple
the gradient usedgradient_len: int
the number of characters in the gradientverbose: boolean
whether or not to do verbose logging
- toascii.Image(filename='image.png', *, scale=1, w_stretch=2, gradient=Union[int, str], verbose=False)
- Note: only filename can be a positional argument, the rest are kwargs.
- Arguments:
filename: str
the name of the file/image which is to be opened and processedscale: str
the amount/1 which the image dimensions are multiplied byw_stretch: float
the amount that the width dimension is multiplied bygradient: float
either an integer from the preset gradients, or a custom gradient Example: '#$a=+-., 'verbose: boolean
whether or not to show extra information
- Functions:
convert()
actually converts the image into asciiview()
view the converted image
- Attributes:
filename: str
the name of the file/video which was opened and processedimage: numpy array
actual numpy array returned fromcv2.imread()
width: int
the unaltered width of the imageheight: int
the unaltered height of the imagescale: float
the scale which is applied to both the dimensions of the imagew_stretch: float
the scale which is only applied to the width dimensionscaled_width: int
the final scaled widthscaled_height: int
the final scaled heightgradient: tuple
the gradient usedgradient_len: int
the number of characters in the gradientverbose: boolean
whether or not to do verbose logging
- toascii.Live(source=0, *, scale=1, w_stretch=2, gradient=Union[int, str], fps=10, verbose=False)
- Note: only source can be a positional argument, the rest are kwargs.
- Arguments:
source: int
the number relating to the video camera to be used, default is 0scale: str
the amount/1 which the source video dimensions are multiplied byw_stretch: float
the amount that the width dimension is multiplied bygradient: int
either an integer from the preset gradients, or a custom gradient Example: '#$a=+-., 'fps: float
the fps used when showing the live video sourceverbose: boolean
whether or not to show extra information
- Functions:
view()
view the live video
- Attributes:
source: int
the name of the file/video which was opened and processedvideo: cv2.VideoCapture
the actualcv2.VideoCapture
objectfps: float
the fps of the live source videowidth: int
the unaltered width of the live source videoheight: int
the unaltered height of the live source videoscale: float
the scale which is applied to both the dimensions of the live source videow_stretch: float
the scale which is only applied to the width dimensionscaled_width: int
the final scaled widthscaled_height: int
the final scaled heightgradient: tuple
the gradient usedgradient_len: int
the number of characters in the gradientverbose: boolean
whether or not to do verbose logging
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for to_ascii-3.4.19-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fd0341c3ebbbb273777963247c625b768b076bf7ee3f9191e2f017576035841 |
|
MD5 | da7d3751e390907cb7374f261ab8a297 |
|
BLAKE2b-256 | 9b4aa90702d07587b18366d234875a4de75e7411eddd635c03f6e2630da3d939 |