-
Notifications
You must be signed in to change notification settings - Fork 0
/
prerender.py
76 lines (52 loc) · 1.63 KB
/
prerender.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
import os
import time
import cv2
from img2colorized_ascii import render, convertFrame, printImageASCII
from util.file_utils import writeJSON_File
"""
Open video, render all the frames
Then save as json / play
"""
def main():
clearScreen = "cls"
pathToVideo = './vid/ricardo.mp4'
outputFile = './rendered_frames.json'
vidcap = cv2.VideoCapture(pathToVideo)
fps = vidcap.get(cv2.CAP_PROP_FPS)
frameAmount = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
vidLen = int(frameAmount / fps)
success, frame = vidcap.read()
d = {}
d['fps'] = fps
d['frame_amount'] = frameAmount
print(f"FPS: {fps}")
print(f"Frame amount: {frameAmount}")
frameCounter = 0
while (success):
k = f'frame_{frameCounter}'
print(f"Rendering ... {k} ({frameCounter + 1} / {frameAmount})")
img = convertFrame(frame)
renderedFrame = render(img)
d[k] = renderedFrame
success, frame = vidcap.read()
frameCounter += 1
vidcap.release()
# Part that saves the rendered frames
print(f"Rendered {frameCounter + 1} frame(s)")
r = writeJSON_File(outputFile, d)
if (r):
print("SUCCESS! Saved rendered frames!")
else:
print("ERROR! Unable to save rendered frames!")
print("--- End of Program ---")
"""
# Part that plays the video after rendering
print("All frames rendered!")
ignored = input("Press Enter to continue...")
os.system(clearScreen)
for k, frame in d.items():
printImageASCII(frame)
time.sleep(1 / 60) # 60 Hz?
"""
if (__name__ == '__main__'):
main()