Best Practice to Python Get Video Duration with MoviePy – Python Tutorial

By | September 11, 2019

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.

MoviePy tutorials and examples

Install moviepy

pip install moviepy

Import libraries

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.

python video duration example

Leave a Reply

Your email address will not be published. Required fields are marked *