-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (33 loc) · 1.01 KB
/
main.py
File metadata and controls
47 lines (33 loc) · 1.01 KB
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
import progressbar
import sys
import videoparser
from PIL import Image, ImageDraw
def usage():
print("usage: main.py video_file output.png")
if len(sys.argv) != 3:
usage()
sys.exit(1)
# Declare a blank image and prepare it for drawing
out_image = Image.new("RGB", (1920, 1080))
out_image_draw = ImageDraw.Draw(out_image, "RGB")
out_frame = 0
video = videoparser.Video(sys.argv[1], frames_wanted=out_image.width,
downscale=2 ** 4)
out_path = sys.argv[2]
widgets = [
progressbar.Percentage(), ' ',
progressbar.Bar(), ' ',
progressbar.AdaptiveTransferSpeed(unit="f"), ' ',
progressbar.ETA()
]
bar = progressbar.ProgressBar(max_value=out_image.width, widgets=widgets)
with bar:
while True:
frame = video.next_frame()
if frame == None:
break
out_image_draw.line([(out_frame, 0), (out_frame, out_image.height)],
fill="rgb" + str(frame.average_color()))
out_frame += 1
bar.update(out_frame)
out_image.save(out_path)