1import cv2
2vidcap = cv2.VideoCapture('big_buck_bunny_720p_5mb.mp4')
3success,image = vidcap.read()
4count = 0
5while success:
6 cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file
7 success,image = vidcap.read()
8 print('Read a new frame: ', success)
9 count += 1
1import cv2
2video_name = "name.mp4" # or any other extension like .avi etc
3vidcap = cv2.VideoCapture(video_name)
4success,image = vidcap.read()
5count = 0
6while success:
7 cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file
8 success,image = vidcap.read()
9 print('Read a new frame: ', success)
10 count += 1
1import numpy as np
2import cv2
3
4cap = cv2.VideoCapture(0)
5
6fourcc = cv2.VideoWriter_fourcc(*'XVID')
7out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))
8
9while(cap.isOpened()):
10 ret, frame = cap.read()
11 if ret==True:
12 frame = cv2.flip(frame,0)
13
14
15 out.write(frame)
16
17 cv2.imshow('frame',frame)
18 if cv2.waitKey(1) & 0xFF == ord('q'):
19 break
20 else:
21 break
22cap.release()
23
24out.release()
25
26cv2.destroyAllWindows()