Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

capture one frame from a video file after every 10 seconds

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
like image 319
ucmou Avatar asked Dec 08 '22 21:12

ucmou


1 Answers

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
like image 79
amaresh hiremani Avatar answered Dec 22 '22 00:12

amaresh hiremani