-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path2_dir_to_vid.py
53 lines (40 loc) · 1.48 KB
/
2_dir_to_vid.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
from conf import SAMPLE_INPUTS, SAMPLE_OUTPUTS
from moviepy.editor import * # ImageClip
from PIL import Image
thumbnail_dir = os.path.join(SAMPLE_OUTPUTS, "thumbnails")
thumbnail_per_frame_dir = os.path.join(SAMPLE_OUTPUTS, "thumbnails-per-frame")
thumbnail_per_half_second_dir = os.path.join(SAMPLE_OUTPUTS, "thumbnails-per-half-second")
output_video = os.path.join(SAMPLE_OUTPUTS, 'thumbs.mp4')
this_dir = os.listdir(thumbnail_dir)
filepaths = [os.path.join(thumbnail_dir, fname) for fname in this_dir if fname.endswith("jpg")]
# filepaths = []
# for fname in this_dir:
# if fname.endswith("jpg"):
# path = os.path.join(thumbnail_dir, fname)
# filepaths.append(path)
# print(filepaths)
# clip = ImageSequenceClip(filepaths, fps=1)
# clip.write_videofile(output_video)
directory = {}
for root, dirs, files in os.walk(thumbnail_per_frame_dir):
for fname in files:
filepath = os.path.join(root, fname)
try:
key = float(fname.replace(".jpg", ""))
except:
key = None
if key != None:
directory[key] = filepath
new_paths = []
for k in sorted(directory.keys()):
filepath = directory[k]
new_paths.append(filepath)
# clip = ImageSequenceClip(new_paths, fps=10)
# clip.write_videofile(output_video)
my_clips = []
for path in list(new_paths):
frame = ImageClip(path)
# print(frame.img) # numpy array
my_clips.append(frame.img)
clip = ImageSequenceClip(my_clips, fps=22)
clip.write_videofile(output_video)