-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddbanner.py
executable file
·93 lines (70 loc) · 2.15 KB
/
addbanner.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
85
86
87
88
89
90
91
92
93
#!/bin/env python
import os, sys, getopt
import ffmpeg
from pprint import pprint
from tempfile import mktemp
import proclib as p
def showhelp():
print("help")
rs = f"""
-h, --help Help
"""
print(rs)
exit()
basedir = os.getcwd()
project = os.getcwd().split("/")[-1]
argv = sys.argv[1:]
debug = False
videofile = False
bannerimg = False
dirs = os.getcwd().split("/")
controlnet = dirs[-1]
sampler = dirs[-2]
model = dirs[-3]
labeltext = f"{model}~+~{sampler}~+~{controlnet}"
try:
opts, args = getopt.getopt(
argv,
"hv:b:d",
["help", "video=" "banner=","debug"],
)
except Exception as e:
print(str(e))
for opt, arg in opts:
if opt in ("-h", "--help"):
showhelp()
if opt in ("-v", "--video"):
videofile = arg
if opt in ("-b", "--banner"):
bannerimg = arg
if opt in ("-d", "--debug"):
debug=True
if opt in ("-t", "--text"):
labeltext = arg
vdat = ffmpeg.probe(videofile)
# pprint(vdat)
# exit()
duration = round(float(vdat["format"]["duration"]))
# pprint(vdat["streams"][0]['height'])
height = int(vdat["streams"][0]['height'])
width = int(vdat["streams"][0]['width'])
# pprint(vdat)
# exit()
duration = round(float(vdat["format"]["duration"]))
# get dimensions, title
# make label
label_tmpfile = f"{mktemp()}_label.png"
label_tmpvid = f"{mktemp()}_vid.mp4"
output = "/tmp/outbanner.mp4"
cmd = f'magick -background black -fill yellow -pointsize 25 -gravity center -font Carlito-Regular -size {width}x50 label:"{labeltext}" {label_tmpfile}'
p.prunlive(cmd,debug = debug)
# create video of label
cmd = f"ffmpeg -y -loglevel error -loop 1 -i /tmp/tmp.png -c:v libx264 -t {duration} -pix_fmt yuv420p -vf scale={width}:50 {label_tmpvid}"
p.prunlive(cmd,debug = debug)
# combine the two videos vertically
cmd = f'ffmpeg -y -loglevel warning -i {label_tmpvid} -i {videofile} -fps_mode passthrough -filter_complex "[0:v][1:v]"vstack=inputs=2:shortest=1"[outv]" -map "[outv]" {output}'
p.prunlive(cmd,debug = debug)
mdirs = p.split_path(videofile)
cmd = f"mv {output} {mdirs['dirname']}/banner_{mdirs['basename']}"
# print(cmd)
p.prunlive(cmd,debug = debug)