I want to capture from a video file one frame after every 10 seconds, So if anyone can help me for that i will be very thankful. my python code is like that:
import cv2
print(cv2.__version__)
vidcap = cv2.VideoCapture('Standoff.avi')
vidcap.set(cv2.CAP_PROP_POS_MSEC,96000)
success,image = vidcap.read()
count = 0
success = True
while success:
success,image = vidcap.read()
print 'Read a new frame: ', success
cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file
cv2.waitKey(200)
count += 1
Here i am capturing frames after 10 conversion of frames.you can use time function and similarly capture frames in if condition statement
import cv2
vidcap = cv2.VideoCapture('testing.mp4')
count = 0
success = True
fps = int(vidcap.get(cv2.CAP_PROP_FPS))
while success:
success,image = vidcap.read()
print('read a new frame:',success)
if count%(10*fps) == 0 :
cv2.imwrite('frame%d.jpg'%count,image)
print('successfully written 10th frame')
count+=1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With