MoviePy is a python library, which can help us to operate video. In this tutorial, we will introduce how to get video duration with it. You can learn and do by following our tutorial.
pip install moviepy
from moviepy.editor import VideoFileClip import datetime
Create a VideoFileClip object with video file
video = 'D:\\demo.mp4' clip = VideoFileClip(video)
Get video druation
duration = clip.duration print("video duration is "+ str(duration) + " seconds")
The output is:
video duration is 856.86 seconds
Convert duration seconds to hour, minute and second
video_time = str(datetime.timedelta(seconds = int(duration))) print(video_time)
The duration of this video is: 0:14:16
This value is correct.