-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_cels_to_video.py
43 lines (33 loc) · 1.26 KB
/
convert_cels_to_video.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
import os
import cv2
def generate_video():
shoot_on_threes = True
shoot_on_twos = False
fps = 24
in_path = "D:/Documents/Programming/PythonCode/kivy_code/cel_animators_pal/image_sequence/"
out_path = in_path
video_name = 'lisa_turnaround.mp4'
images = [img for img in os.listdir(in_path) if img.endswith(".jpg") or
img.endswith(".jpeg") or img.endswith(".png")]
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
frame = cv2.imread(os.path.join(in_path, images[0]))
# setting the frame width, height width
# the width, height of first image
height, width, layers = frame.shape
video = cv2.VideoWriter(os.path.join(in_path, video_name), fourcc, 24, (width, height))
print("video: ", video_name)
# Appending the images to the video one by one
for image in images:
if shoot_on_threes == True:
for frame_hold in range(3):
video.write(cv2.imread(os.path.join(in_path, image)))
elif shoot_on_twos == True:
for frame_hold in range(2):
video.write(cv2.imread(os.path.join(in_path, image)))
else:
video.write(cv2.imread(os.path.join(in_path, image)))
print("frame: ", os.path.join(in_path, image))
# Deallocating memories taken for window creation
cv2.destroyAllWindows()
video.release() # releasing the video generated
generate_video()