Skip to content

Instantly share code, notes, and snippets.

@Merwanski
Last active April 8, 2024 09:46
Show Gist options
  • Save Merwanski/d01265b015c504473b33ca77f8053cb9 to your computer and use it in GitHub Desktop.
Save Merwanski/d01265b015c504473b33ca77f8053cb9 to your computer and use it in GitHub Desktop.
photo_2_video
import cv2
import os
import numpy as np
import glob
video_file_name = 'FILE_NAME.mp4'
path_to_images = 'PATH'
extension = "png" # png, jpg, ...
cmpt = 0
myimages = [] #list of image filenames
dirFiles = os.listdir(path_to_images) #list of directory files
dirFiles.sort() #good initial sort but doesnt sort numerically very well
sorted(dirFiles) #sort numerically in ascending order
start = 1
for filename in dirFiles: # glob.glob(path_to_images):
if extension in filename:
img = cv2.imread(os.path.join(path_to_images, filename))
height, width, layers = img.shape
size = (width, height)
print ("[INFO] {} / {}".format(cmpt, len(dirFiles)))
if cmpt == 0:
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
out = cv2.VideoWriter(video_file_name, fourcc, 10, size)
out.write(img)
cmpt = cmpt +1
start = start +1
if start > 100:
break
else:
continue
out.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment