Is their a python module that can get the dimensions of a video file?

Recommended Answers

All 4 Replies

What video file format are you talking about?

mainly mpeg4, this can vary from divx, to xvid, and other mpeg4 formats. I want a simple program to help he write a config file that is passed to mplayer(avi player). To have the config file automatically written, I need the original WxH. I have found a program that runs on linux that would work, but would still be insterested in using a python module

this is the linux command line program called avitype

shane@mainbox shane $ avitype movies/collateral2/collateral.avi | grep WxH
 InitialFrames=0 Streams=2 SuggestedBufferSize=0 WxH=650x366

I am specifiacally looking for this data 650,366

using the linux program avitype, I have written this function. It still would be nice to find an all python way of doing it

# this python function gets the dimensions of a video file and returns them as a tuple (width,height)
# it uses the linux video program avitype (I think this is part of the transcode package)

# getdimensions.py

def getdimensions(video_file):

    import commands
    avitype_command= "/usr/bin/avitype %s | grep WxH" % video_file
    dimensions = commands.getoutput(avitype_command)
    width = dimensions[-7:-4]
    height = dimensions[-3:]
    WxH = (width,height)
    return WxH

I have never managed to get my hands on a linux box, this sounds interesting. I have done some work with the Windows avi player in my C++ days mostly through shared COM.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.