Skip to content

Instantly share code, notes, and snippets.

@chaojian-zhang
Last active June 26, 2022 03:26
Show Gist options
  • Save chaojian-zhang/38545bcd9715ae8d60576ed38f3bb4e4 to your computer and use it in GitHub Desktop.
Save chaojian-zhang/38545bcd9715ae8d60576ed38f3bb4e4 to your computer and use it in GitHub Desktop.
Video Capture (Python,Cv2)
# This is VERY INEFFICIENT - at the moment for 10min video it produces 10*60*25=15000 images
# The framerate calculation is WRONG: it's NOT taking screenshots every 10 frames, but it's taking every frame!
# In fact, it's faster and more efficient if we just re-watch the video in VLC and use Alt-V-S shortcut to take screenshots when needed
import cv2
vidcap = cv2.VideoCapture('temp.mp4')
framerate = vidcap.get(cv2.CAP_PROP_FPS)
success,image = vidcap.read()
count = 0
while success:
if count % (framerate * 10) ==0:
cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file
success,image = vidcap.read()
print('Read a new frame: ', success)
count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment