Let’s see how to play video using OpenCV Python.
To capture video, we need to create a VideoCapture object
. VideoCapture has a device index or video file name. Device index — it’s just a number indicating which camera. If we pass 0, that’s for the first camera , 1 for the second camera, and so on. We shoot video frame by frame.
Syntax :
cv2.VideoCapture (0): Means first camera or webcam. cv2.VideoCapture (1): Means second camera or webcam. cv2.VideoCapture ("file name.mp4"): Means video file
Below is the implementation:
|
Note. The video file must be in the same directory where the program is running.
Exit :
Sample video frame:
Related article: How to play video in reverse .