I want to save frames from a video. My problem is that saved frames keep overwriting and only last frame saved at the end. Here is my code
import cv2
vc = cv2.VideoCapture('111.mp4')
c = 1
if vc.isOpened():
rval, frame = vc.read()
else:
rval = False
timeF = 30
while rval:
rval, frame = vc.read()
if not rval: break
if (c % timeF == 0):
cv2.imwrite('/home/benson/Image/imagename.jpg', frame)
c = c + 1
cv2.waitKey(1)
vc.release()
You already have a counter available, why aren't you using it?
cv2.imwrite('/home/benson/Image/imagename_{:04d}.jpg'.format(c), frame)
Good luck
Andreas
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.