我想每 10 秒后从视频文件中捕获一帧,所以如果有人可以帮助我,我将非常感激。我的python代码是这样的:

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

最佳答案

在这里,我在 10 帧转换后捕获帧。您可以使用时间函数并在 if 条件语句中类似地捕获帧

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

关于python - 每 10 秒后从视频文件中捕获一帧,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39622281/

10-15 17:41