10 examples of 'python read video frames' in Python

Every line of 'python read video frames' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
14def read(self):
15 if not self.is_ok:
16 raise RuntimeError("Error opening video stream or file")
17
18 self.is_ok, frame = self.cap.read()
19 return self.is_ok, frame
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

43def read(self):
44 src_img = pyMTF2.getFrame()
45 if src_img is None:
46 print('Frame extraction was unsuccessful')
47 return 0, None
48 return 1, src_img
4def get_frames(video_path, number_of_frames=1):
5 video_feed = cv2.VideoCapture(video_path)
6
7 frames = []
8
9 ret = True
10 for i in range(number_of_frames):
11 ret, frame = video_feed.read()
12
13 if ret:
14 frames.append(frame)
15
16 video_feed.release()
17 return frames
60def captureFrame(self):
61 """
62 capture frame and return captured frame
63 """
64 ret, readFrame = self.capture.read()
65 return readFrame
24def getframe(self): # returns tuple --> ret, frame
25
26 return self.data.read()
91def video_frames(filename):
92 """Yield frames in a video."""
93 cap = cv2.VideoCapture(args.video)
94 while True:
95 ret, frame = cap.read()
96 if ret:
97 yield frame
98 else:
99 break
100 cap.release()
12def extract_frames(video_path):
13
14 def convert_frame(arg):
15 return Image.fromarray(arg[:, :, :3], mode='RGB')
16
17 video_reader = imageio.get_reader(video_path)
18 fps = video_reader.get_meta_data().get('fps', None)
19 frames = [convert_frame(x) for x in video_reader]
20
21 return frames, fps
8def test_nvdec_read_frame(video_filename, first_frame_image):
9 backend = NvdecBackend()
10
11 inst = backend.create(video_filename, 'cuda:0')
12 rgb = inst.read_frame()
13
14 assert(rgb.size() == (3, 720, 1280))
15
16 rgb_bytes = (rgb * 255).round_().byte().cpu()
17 img = PIL.Image.fromarray(rgb_bytes.permute(1, 2, 0).numpy(), 'RGB')
18
19 np.testing.assert_allclose(img, first_frame_image, rtol=0, atol=50)
53def load_video():
54 manager_cv2 = ManagerCV2(cv2.VideoCapture('walking.mp4'), is_stream=False, fps_limit=3)
55 manager_cv2.add_keystroke(27, 1, print, 'Pressed esc. Exiting', exit=True)
56 storage_cv2 = StorageCV2(path='salida.json')
57
58 for frame, selector in zip(manager_cv2,storage_cv2):
59 frame = cv2.flip(frame, 1)
60 frame = selector.draw(frame)
61 cv2.imshow('Example face_recognition', frame)
62 print('FPS: {}'.format(manager_cv2.get_fps()))
63 cv2.destroyAllWindows()
41def frames_to_video(self, frames, fps):
42 logging.info('Combining frames')
43 fourcc = cv2.VideoWriter_fourcc('D', 'I', 'V', 'X')
44 resolution = frames[0].shape[:2][::-1]
45 out = cv2.VideoWriter(self.__path_out, fourcc, fps, resolution)
46 for frame in frames:
47 out.write(frame)
48 out.release()

Related snippets