Skip to content

Commit

Permalink
validating the issue when non existing the required output location
Browse files Browse the repository at this point in the history
  • Loading branch information
PawaraGunawardena committed Mar 1, 2019
1 parent 0fb6b40 commit 9d2e659
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/frames_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
from os.path import isfile, join

def convert_frames_to_video(input_frames_path, output_video_path, fps):
def convert_frames_to_video(input_frames_path, output_video_path, output_video_name, fps):

if (os.path.isdir(input_frames_path)):

Expand All @@ -28,6 +28,14 @@ def convert_frames_to_video(input_frames_path, output_video_path, fps):
files.sort(key=lambda x: int(x[5:-4]))

if(len(files)!=0):

try:
# validate the exitence of the output location to save the output video
if not os.path.exists(output_video_path):
os.makedirs(output_video_path)
except OSError:
print('Error: Creating directory of data')

for i in range(len(files)):
# reading image files
filename = input_frames_path + files[i]
Expand All @@ -40,7 +48,7 @@ def convert_frames_to_video(input_frames_path, output_video_path, fps):
frame_array.append(img)

# Initiate the output video file
out = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
out = cv2.VideoWriter(output_video_path+output_video_name, cv2.VideoWriter_fourcc(*'DIVX'), fps, size)

for i in range(len(frame_array)):
# writing to a image array
Expand All @@ -52,10 +60,11 @@ def convert_frames_to_video(input_frames_path, output_video_path, fps):
print("Given path of the frames not exists.")

def run():
input_frames_path = "./data/generated_frame/"
output_video_path = "./data/output_video/output_video.avi"
input_frames_path = "./data/generated_frames/"
output_video_path = "./data/output_video/"
output_video_name = "output_video.avi"
fps = 25.0
convert_frames_to_video(input_frames_path, output_video_path, fps)
convert_frames_to_video(input_frames_path, output_video_path, output_video_name, fps)

if __name__ == "__main__":
run()

0 comments on commit 9d2e659

Please sign in to comment.