python get frames from video code example
Example 1: mp4 get all images frame by frame python
import cv2
vidcap = cv2.VideoCapture('big_buck_bunny_720p_5mb.mp4')
success,image = vidcap.read()
count = 0
while success:
cv2.imwrite("frame%d.jpg" % count, image)
success,image = vidcap.read()
print('Read a new frame: ', success)
count += 1
Example 2: extract frames from video python
import cv2
video_name = "name.mp4"
vidcap = cv2.VideoCapture(video_name)
success,image = vidcap.read()
count = 0
while success:
cv2.imwrite("frame%d.jpg" % count, image)
success,image = vidcap.read()
print('Read a new frame: ', success)
count += 1