-
Notifications
You must be signed in to change notification settings - Fork 6
/
__main__.py
85 lines (71 loc) · 3.36 KB
/
__main__.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def getArgs():
import argparse
parser = argparse.ArgumentParser(description='碧蓝航线绘图日记像素画生成工具')
parser.add_argument('input', metavar='input', type=str, help='input file path')
parser.add_argument('-o', '--output', type=str, help='output file path. image end by .png,video end by .avi')
parser.add_argument('-m', '--mode', type=str, help='mode to run this program',
choices=["video", "image"], default=None)
parser.add_argument('-b', '--bold', type=int, help='bold of lines of images,integer', default=0)
parser.add_argument('-x', '--width', type=int, help='width to run', default=1)
parser.add_argument('-y', '--height', type=int, help='height to run', default=1)
parser.add_argument('-c', '--cutFrames', type=int,
help='extrace one frame in cutFrame(your input num) frames,mode video only', default=1)
# parser.add_argument('-c', '--cutFrames', type=int, help='extrace one frame in cutFrame(your input num) frames,mode video only',default=1)
args = parser.parse_args()
return args
def mainFunc(args):
import os
if not os.path.exists(args.input):
print("error: input file not found!")
return
if args.mode == None:
fileTypeS = args.input.split(".")[-1]
imageTypess = ("png","jpg","jpeg","bmp")
videoTypess = ("flv", "mp4", "avi", "mkv", "wma", "rmvb","mov")
fileTypeSLower = fileTypeS.lower()
if fileTypeSLower in imageTypess:
args.mode = "image"
elif fileTypeSLower in videoTypess:
args.mode = "video"
else:
print("error: con't identify you input file mode,please appoint mode by -m argument")
if args.mode == "image":
print(f"start draw image {args.input}......")
import paint
# if args.x is None:
# args.x = 1
# if args.y is None:
# args.y = 1
o = paint.drawN(imgPath=args.input, w=args.width, h=args.height, blur=args.bold)
if not args.output is None:
oPath = args.output
else:
import time
absInputPath = os.path.abspath(args.input)
oPaths = os.path.split(absInputPath)
rawFileName = oPaths[1]
outFileName = f"{rawFileName.split('.')[0]}-{int(time.time())}.png"
oPath = os.path.join(oPaths[0], outFileName)
# oPath = f"azurlanePainting-{int(time.time())}.png"
o.save(oPath, "PNG")
print(f"image drawn completed -> {oPath}")
elif args.mode == "video":
print(f"start handdle video {args.input}......")
import analyseVideo
if not args.output is None:
oPath = args.output
else:
import time
absInputPath = os.path.abspath(args.input)
oPaths = os.path.split(absInputPath)
outFileName = f"{oPaths[1].split('.')[0]}-{int(time.time())}.avi"
oPath = os.path.join(oPaths[0], outFileName)
# import time
#
# oPath = f"azurlanePainting-{int(time.time())}.avi"
analyseVideo.makeVideo(inputVideoPath=args.input, output=oPath, cutFrames=args.cutFrames, w=args.width,
h=args.height, blur=args.bold)
print(f"video handdled completed -> {oPath}")
if __name__ == '__main__':
args = getArgs()
mainFunc(args)