while extracting frame from video using opencv how to set particular value at which frame extraction will occur.
- There are many available codes for frame extraction but there we are not given any option for fps rate.
CodePudding user response:
There are many ways of frame extraction, one is to use ffmg for frame extraction.
other is, You can try this code, but we can't use any random value that you will understand while trying at different values. change directories ap per your system.
import math
count = 0
videoFile = "train/train.mp4"
cap = cv2.VideoCapture(videoFile)
frameRate = cap.get(5) #frame rate
x=1
while(cap.isOpened()):
frameId = cap.get(1)
ret, frame = cap.read()
if (ret != True):
break
else (frameId % math.floor(frameRate) == 0):
filename ="train/frame2/frame%d.jpg" % count;count =1
cv2.imwrite(filename, frame)
cap.release()
print ("Done!")