In this blog post, this is a rude solution in python:
import subprocess, re pattern = re.compile(r'Stream.*Video.*([0-9]{3,})x([0-9]{3,})') def get_size(pathtovideo): p = subprocess.Popen(['ffmpeg', '-i', pathtovideo], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() match = pattern.search(stderr) if match: x, y = map(int, match.groups()[0:2]) else: x = y = 0 return x, y
This, however, assumes that it is 3 digits x 3 digits (i.e. 854x480), you will need to skip the possible measurement lengths, for example (1280x720):
possible_patterns = [re.compile(r'Stream.*Video.*([0-9]{4,})x([0-9]{4,})'), \ re.compile(r'Stream.*Video.*([0-9]{4,})x([0-9]{3,})'), \ re.compile(r'Stream.*Video.*([0-9]{3,})x([0-9]{3,})')]
and check if no one returns at each step:
for pattern in possible_patterns: match = pattern.search(stderr) if match!=None: x, y = map(int, match.groups()[0:2]) break if match == None: print "COULD NOT GET VIDEO DIMENSIONS" x = y = 0 return '%sx%s' % (x, y)
It may be prettier, but it works.