Python OpenCV
About Lesson

In this Python OpenCV lesson we are going to learn How to Play Mp4 Videos in Python OpenCV, before this we have learned that how you can read avi videos in opencv, you can use an mp4 video or you can use camera, the same code will be implemented with camera or mp4 video.



This is the complete code for this lesson.



In here we are loading our mp4 video, make sure that you have already added a video in your working directory, if you are using camera you need to give 0 in cap = cv2.VideoCapture(‘mp4vid.mp4’).





Check if the video capture is opened, if it is not opened give error.




Using this code we are reading our video, and we are checking if the video capture is opened we want to read the cap and show the frame, if we press the q key we want to close the video.