Skip to content

Instantly share code, notes, and snippets.

@deepwilson
Last active October 20, 2018 06:48
Show Gist options
  • Save deepwilson/1b1288750df202d0226efe6af02a5959 to your computer and use it in GitHub Desktop.
Save deepwilson/1b1288750df202d0226efe6af02a5959 to your computer and use it in GitHub Desktop.
Get duration of a video using 'ffprobe'
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