Skip to content

Instantly share code, notes, and snippets.

@aravindpai
Created April 28, 2020 16:17
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 aravindpai/242884bdea43468f2546770a525dbd82 to your computer and use it in GitHub Desktop.
Save aravindpai/242884bdea43468f2546770a525dbd82 to your computer and use it in GitHub Desktop.
%%time
!rm -r frames/*
!mkdir frames/
#specify path to video
video = "sample.mp4"
#capture video
cap = cv2.VideoCapture(video)
cnt=0
# Check if video file is opened successfully
if (cap.isOpened()== False):
print("Error opening video stream or file")
ret,first_frame = cap.read()
#Read until video is completed
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
#save each frame to folder
cv2.imwrite('frames/'+str(cnt)+'.png', frame)
cnt=cnt+1
if(cnt==750):
break
# Break the loop
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment