Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Oct 3, 2020
Embed
What would you like to do?
def extract_multiple_videos(intput_filenames, image_path_infile):
"""Extract video files into sequence of images."""
i = 1 # Counter of first video
# Iterate file names:
cap = cv2.VideoCapture('your_video_file_path.avi' or intput_filenames)
if (cap.isOpened()== False):
print("Error opening file")
# Keep iterating break
while True:
ret, frame = cap.read() # Read frame from first video
if ret:
cv2.imwrite(os.path.join(image_path_infile , str(i) + '.jpg'), frame) # Write frame to JPEG file (1.jpg, 2.jpg, ...)
# you can uncomment this line if you want to view them.
# cv2.imshow('frame', frame) # Display frame for testing
i += 1 # Advance file counter
else:
# Break the interal loop when res status is False.
break
cv2.waitKey(50) #Wait 50msec
cap.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment