Skip to content
Advertisement

Using ffmpeg to obtain video durations in python

I’ve installed ffprobe using the pip ffprobe command on my PC, and installed ffmpeg from here.

However, I’m still having trouble running the code listed here.

I try to use the following code unsuccessfully.

JavaScript

Does anyone know what’s wrong? Am I not referencing the directories correctly? Do I need to make sure the .py and video files are in a specific location?

JavaScript

Apologies if the question is somewhat basic. All I need is to be able to iterate over a group of video files and get their start time and end time.

Thank you!

Advertisement

Answer

There is no need to iterate though the output of FFprobe. There is one simple command which returns only the duration of the input file:

JavaScript

You can use the following method instead to get the duration:

JavaScript
Advertisement