Last active
September 19, 2021 16:27
-
-
Save fossbalaji/c27d294707f5444ff176 to your computer and use it in GitHub Desktop.
How to get video file duration and resolution in python
This file contains 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 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] | |
if line.rfind("Video") > 0: | |
resolution = re.findall("(\d+x\d+)", line)[0] | |
return duration,resolution | |
# call function with file path | |
getvideodetails("/home/bala/sample.mp4") # change this line to your video file path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Incase avconv command not found, In debain based systems
sudo apt-get install libav-tools