Skip to content

Instantly share code, notes, and snippets.

@svmihar
Created February 26, 2020 08:36
Show Gist options
  • Save svmihar/8dafdc59df36621298f139ad2db0ef3f to your computer and use it in GitHub Desktop.
Save svmihar/8dafdc59df36621298f139ad2db0ef3f to your computer and use it in GitHub Desktop.
import cv2
import os
def extractFrames(pathIn, pathOut):
os.mkdir(pathOut)
cap = cv2.VideoCapture(pathIn)
count = 0
while (cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
print('Read %d frame: ' % count, ret)
cv2.imwrite(os.path.join(pathOut, "frame{:d}.jpg".format(count)), frame) # save frame as JPEG file
count += 1
else:
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
def main():
extractFrames('bigbuckbunny720p5mb.mp4', 'data')
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment