Skip to content

Instantly share code, notes, and snippets.

View fossbalaji's full-sized avatar

Balaji.G fossbalaji

View GitHub Profile
@fossbalaji
fossbalaji / duration.py
Last active September 19, 2021 16:27
How to get video file duration and resolution in python
from subprocess import Popen, PIPE
import re
def getvideodetails(filepath):
cmd = "avconv -i %s" % filepath
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
di = p.communicate()
for line in di:
if line.rfind("Duration") > 0:
duration = re.findall("Duration: (\d+:\d+:[\d.]+)", line)[0]