-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.py
46 lines (40 loc) · 1.35 KB
/
create.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
from shutil import rmtree
import subprocess
import os
import sys
import tqdm
import argparse
psr = argparse.ArgumentParser(
prog="ASCII Animation Generator",
usage="python3 create.py <OPTIONS>",
description="Generate ASCII animation from video file."
)
# psr.add_argument("-f", "--file", help="<path/to/video>")
psr.add_argument("-i", "--input", required=True, help="<Video URL/Video Path>")
psr.add_argument("-t", "--type", required=True, help="url/file")
args = psr.parse_args()
if os.path.isdir('./imgs'):
rmtree('./imgs')
if os.path.isdir('./txts'):
rmtree('./txts')
if os.path.isfile('./video.mp4'):
os.remove('./video.mp4')
if args.type == "url":
dl_cmd = "yt-dlp {} -o video.mp4 -f mp4".format(args.input)
dl = subprocess.run(dl_cmd, shell=True)
if dl.returncode != 0:
sys.exit("something wrong")
fname = "video.mp4"
elif args.type == "file":
fname = args.input
else:
sys.exit("Please select correct type")
os.mkdir('./imgs')
strip = "ffmpeg -i {} -vf fps=30 -vcodec png imgs/%07d.png".format(fname)
subprocess.run(strip, shell=True)
imgs = os.listdir('./imgs')
os.mkdir('./txts')
for img in tqdm.tqdm(imgs):
convert = "jp2a imgs/{} --output=txts/{} --size=96x54".format(img, img.replace('png', 'txt'))
subprocess.run(convert, shell=True)