Get video duration using Python – OpenCV
OpenCV is one of the most popular cross-platform libraries and it is widely used in Deep Learning, image processing, video capturing, and many more. In this article, we will learn how to get the duration of a given video using python and computer vision.
Opencv can be downloaded by running the given command on the terminal:
pip install Opencv
To get the duration of a video, following steps has to be followed:
- Import required modules.
- Create a VideoCapture object by providing video URL to VideoCapture() method.
- Count the total numbers of frames and frames per second of a given video by providing cv2.CAP_PROP_FRAME_COUNT and cv2.CAP_PROP_FPS to get() method.
- Calculate the duration of the video in seconds by dividing frames and fps.
- Also, calculate video time using timedelta() method.
Below is the implementation.
duration in seconds: 32 video time: 0:00:28
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course