-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathimage_to_video_converter.py
34 lines (26 loc) · 1.12 KB
/
image_to_video_converter.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
import cv2
import os
def images_to_video(images, video_path, fps):
if images:
frame = images[0]
height, width, layers = frame.shape
if '.' not in video_path:
video_path += '.avi'
video = cv2.VideoWriter(video_path, 0, fps, (width,height))
for image in images:
video.write(image)
cv2.destroyAllWindows()
video.release()
def image_folder_to_video(image_folder, video_path, fps):
images = [cv2.imread(os.path.join(image_folder, img))
for img in os.listdir(image_folder)
if img.endswith(".png")]
images_to_video(images, video_path, fps)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--image_folder', required=True, help='Location of the image folder')
parser.add_argument('--video_path', required=True, help='Path to the output video')
parser.add_argument('--fps', type=int, default=30)
args = parser.parse_args()
image_folder_to_video(args.image_folder, args.video_path, args.fps)