Skip to content

Instantly share code, notes, and snippets.

@biparnakroy
Last active May 16, 2020 21:26
Show Gist options
  • Select an option

  • Save biparnakroy/a24e3a5e78497e57721bbbf226d15355 to your computer and use it in GitHub Desktop.

Select an option

Save biparnakroy/a24e3a5e78497e57721bbbf226d15355 to your computer and use it in GitHub Desktop.

Frame extractor from video

import cv2
import numpy as np
import math

cap= cv2.VideoCapture("vid.avi")
frameRate = cap.get(5) #frame rate
x=5050
while True:
    frameId = cap.get(1)
    _, frame =cap.read()
    #uncomment if you want to rotate the frames
    #frame=cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE)
    if (frameId % (math.floor(frameRate)*5) == 0):
        filename = 'images/mox' +  str(int(x)) + ".jpg";x+=1
        cv2.imwrite(filename, frame)
cap.release()
print ("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment