Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created October 3, 2020 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/5914e71f17d94f1f2a3fb09faf0dcd5e to your computer and use it in GitHub Desktop.
Save amankharwal/5914e71f17d94f1f2a3fb09faf0dcd5e to your computer and use it in GitHub Desktop.
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