Last active
October 20, 2018 06:48
-
-
Save deepwilson/1b1288750df202d0226efe6af02a5959 to your computer and use it in GitHub Desktop.
Get duration of a video using 'ffprobe'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import check_output | |
import re | |
file_name = "movie.mp4" | |
#For Windows | |
a = str(check_output('ffprobe -i "'+file_name+'" 2>&1 |findstr "Duration"',shell=True)) | |
#For Linux | |
#a = str(check_output('ffprobe -i "'+file_name+'" 2>&1 |grep "Duration"',shell=True)) a = a.split(",")[0].split("Duration:")[1].strip() | |
a = re.findall(r"\bDuration: (\d+:\d+:\d+\.\d+)\b",a)[0] | |
h, m, s = a.split(':') | |
duration = int(h) * 3600 + int(m) * 60 + (float(s)) | |
print(duration) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment