Reading (cam.read()) from a VideoCapture returns a tuple (return value, image). With the first item you check wether the reading was successful, and if it was then you proceed to use the returned image.

This is documented at https://opencv-tutorial.readthedocs.io/en/latest/intro/intro.html#capture-live-video

Answer from mmgp on Stack Overflow
🌐
Roboflow
roboflow.com › home › read video streams with cv2.videocapture
Read Video Streams with cv2.VideoCapture (OpenCV) | Roboflow
import cv2 as cv cap = cv.VideoCapture(0) while True: ret, frame = cap.read() if not ret: break cv.imshow('frame', frame) if cv.waitKey(1) == ord('q'): break cap.release() cv.destroyAllWindows()
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-opencv-capture-video-from-camera
Python OpenCV: Capture Video from Camera - GeeksforGeeks
July 12, 2025 - Create a VideoWriter object to save captured frames as a video in the computer. Set up an infinite while loop and use the read() method to read the frames using the above created object.
🌐
LearnOpenCV
learnopencv.com › home › image processing › reading and writing videos using opencv
Reading and Writing Videos using OpenCV | LearnOpenCV
October 15, 2025 - Just specify the image files which are being read. ... Using the notation shown below (Carsd.jpg), where d indicates a four-digit sequence-naming convention (e.g. Cars0001.jpg, Cars0002.jpg, Cars0003.jpg, etc). If you had specified “Race_Cars_d.jpg” then you would be looking for files of the form: (Race_Cars_01.jpg, Race_Cars_02.jpg, Race_Cars_03.jpg, etc…). All other codes described in the first example would be the same. vid_capture = cv2.VideoCapture('Resources/Image_sequence/Carsd.jpg')
🌐
Scaler
scaler.com › home › topics › opencv cv2.videocapture() function
OpenCV cv2.VideoCapture() Function - Scaler Topics
June 23, 2023 - To use cv2.VideoCapture(), you ... access to the video stream. Once the VideoCapture object has been created, you can use the read() method to read frames from the video stream....
🌐
OpenCV
opencv.org › home › news › reading and writing videos using opencv
Reading and Writing Videos using OpenCV
March 28, 2025 - To write a video in OpenCV, we first open the video file using cv2.VideoCapture() in Python or cv::VideoCapture in C++. After successfully opening the video, we retrieve its properties, such as frame width and height, using cv2.CAP_PROP_FRAME_WIDTH and cv2.CAP_PROP_FRAME_HEIGHT. Next, we set up the video writer by defining the codec with cv2.VideoWriter_fourcc() in Python or cv::VideoWriter::fourcc() in C++, specifying the FPS and resolution. Inside a loop, we continuously read frames using cap.read(), write each frame to the output video using out.write(frame), and display it using cv2.imshow().
🌐
Cloudinary
cloudinary.com › home › getting started with cv2 video capture in python
Getting Started with cv2 Video Capture in Python | Cloudinary
April 12, 2026 - To use it, you first create an ... which gives you access to the video stream. Once created, you can call the read() method to retrieve frames....
🌐
LearnOpenCV
learnopencv.com › home › read, write and display a video using opencv
Read, Write and Display a video using OpenCV | LearnOpenCV
July 31, 2026 - The Python and C++ implementation of reading and displaying a video file follows. ... import cv2 import numpy as np # Create a VideoCapture object and read from input file # If the input is the camera, pass 0 instead of the video file name cap = cv2.VideoCapture('chaplin.mp4') # Check if camera opened successfully if (cap.isOpened()== False): print("Error opening video stream or file") # Read until video is completed while(cap.isOpened()): # Capture frame-by-frame ret, frame = cap.read() if ret == True: # Display the resulting frame cv2.imshow('Frame',frame) # Press Q on keyboard to exit if cv2.waitKey(25) & 0xFF == ord('q'): break # Break the loop else: break # When everything done, release the video capture object cap.release() # Closes all the frames cv2.destroyAllWindows()
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python › opencv
Capture video from camera/file with OpenCV in Python | note.nkmk.me
October 19, 2022 - You can get the frames of the video ... with the read() method of the VideoCapture object. For video files, you need to consider the current position. You can get the current number of frames and the elapsed time in milliseconds with the get() ...
🌐
OpenCV
docs.opencv.org › 4.13.0 › dd › d43 › tutorial_py_video_display.html
OpenCV: Getting Started with Videos
import cv2 as cv · cap = cv.VideoCapture('vtest.avi') while cap.isOpened(): ret, frame = cap.read() # if frame is read correctly ret is True · if not ret: print("Can't receive frame (stream end?). Exiting ...") break · gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) cv.imshow('frame', gray) if cv.waitKey(1) == ord('q'): break ·
🌐
Python Programming
pythonprogramming.net › loading-video-python-opencv-tutorial
Loading Video Source OpenCV Python Tutorial
import numpy as np import cv2 cap = cv2.VideoCapture(0) while(True): ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('frame',gray) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
🌐
OpenCV-Python Tutorials
opencv24-python-tutorials.readthedocs.io › en › latest › py_tutorials › py_gui › py_video_display › py_video_display.html
Getting Started with Videos — OpenCV-Python Tutorials beta documentation
import numpy as np import cv2 cap = cv2.VideoCapture(0) while(True): # Capture frame-by-frame ret, frame = cap.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the resulting frame cv2.imshow('frame',gray) if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() cv2.destroyAllWindows()
🌐
GitHub
github.com › opencv › opencv › issues › 24393
How to avoid blocking with cv2.VideoCapture.read()? · Issue #24393 · opencv/opencv
October 12, 2023 - cap = cv2.VideoCapture("rtsp://......") while True: ret, frame = cap.read() if not ret: break cv2.imshow("test", frame) cv2.waitKey(1) cap.release() while i closed the rtsp stream, the code will block at "ret, frame = cap.read()", without any information returned how to avoid blocking with cv2.VideoCapture.read()?
🌐
DataFlair
data-flair.training › blogs › opencv-video-capture
Video Capture with OpenCV - DataFlair
April 3, 2024 - In this code example, we start by creating a VideoCapture object named cap, where we specify the video file (‘video.mp4’) we want to read. Then, we enter a loop where we continuously read frames from the video using cap.read(). The ret variable indicates whether a frame was successfully read. If the frame is successfully read, we display it using cv2.imshow().
🌐
Java2Blog
java2blog.com › home › python › python | cv2 videocapture() method
Python | cv2 VideoCapture() method - Java2Blog
May 23, 2020 - In this tutorial, we will see how ... a given video file. Example 2: Start a webcam. You can use VideoCapture() method of cv2 library to read and start live streaming....
🌐
StudyRaid
app.studyraid.com › en › read › 14915 › 513865 › reading-video-files-with-cv2videocapture
Understand reading video files with cv2.VideoCapture()
import cv2 cap = cv2.VideoCapture('input_video.mp4') if not cap.isOpened(): print("Error opening video file") Video files are read frame-by-frame using a loop. cap.read() returns a tuple: a boolean (ret) indicating success, and the captured frame.
🌐
OpenCV
docs.opencv.org › 4.13.0 › d8 › dfe › classcv_1_1VideoCapture.html
OpenCV: cv::VideoCapture Class Reference
The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the most convenient method for reading video files or capturing data from decode and returns the just grabbed frame.
🌐
Master Data Science
datahacker.rs › 001-how-to-read-a-video-and-access-a-webcam-with-opencv-in-python
#001 How to read a video and access a webcam with OpenCV in Python?
August 15, 2020 - Variable ret is a boolean data type that returns True if we are able to execute the read function successfully. Our frame can be loaded as a color image (it will have 3 channels) or grayscale image (it will have 1 channel). If we need more then one frame we will use “for” or “while” loops. We will explain that in more detail in the further text. # Create a Videocapture object # we want to access a video camera cap=cv2.VideoCapture(0)