Created
July 5, 2020 10:10
-
-
Save neelriyer/d9d30ebaff884a8c13e78692907bc723 to your computer and use it in GitHub Desktop.
Stitch all images together to form video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import os | |
clean = 'seinfeld_inference.mp4' | |
cap = cv2.VideoCapture(clean) | |
clean_fps = cap.get(cv2.CAP_PROP_FPS) | |
print(clean_fps) | |
pathOut = 'video.mp4' | |
try: | |
os.remove(pathOut) | |
except: | |
pass | |
fps = clean_fps | |
frame_array = [] | |
files = sorted(glob.glob('seinfeld_inference/high_res/*_unsquared.*g'), key = lambda x: int(os.path.basename(x).split('.')[0].split('_')[0])) | |
print(len(files)) | |
for i in range(len(files)): | |
filename=files[i] | |
# reading each files | |
img = cv2.imread(filename) | |
height, width, layers = img.shape | |
size = (width,height) | |
# inserting the frames into an image array | |
frame_array.append(img) | |
out = cv2.VideoWriter(pathOut,cv2.VideoWriter_fourcc(*'MP4V'), fps, size) | |
for i in range(len(frame_array)): | |
# writing to a image array | |
out.write(frame_array[i]) | |
out.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment