#!/usr/bin/env python import sys import block import struct import re f = open(sys.argv[1],'r') file = f.read() (riffheader,filesize,format) = struct.unpack("4sI4s",file[0:12]) print "RIFF header: %s" % riffheader print "filesize %i" % filesize print "Format: %s" % format print "------" (listchunk,listsize,listfourcc) = struct.unpack("4sI4s",file[12:24]) print "List chunk: %s" % listchunk print "List size: %i" % listsize print "List 4cc: %s" % listfourcc print "------" (aviheader,avihdrsize,microsecperframe,maxbytespersec,paddinggran,flags,totalFrames, initialFrames,streams,suggestedBufferSize,width,height,reserved) = struct.unpack("4sIIIIIIIIIIII",file[24:76]) print "AVI header: %s" % aviheader print "AVI header size %i" % avihdrsize fps = 0 if (microsecperframe != 0): fps = 1.0/(microsecperframe / 1000000.0) print "%i us/frame (%i fps)" % (microsecperframe, fps) print "%i bytes/sec" % maxbytespersec print "padding granularity %i" % paddinggran print "flags %8.X" % flags print "total frames %i" % totalFrames print "initial frames %i" % initialFrames print "streams %i" % streams print "suggestedBufferSize %i" % suggestedBufferSize print "width %i" % width print "height %i" % height print "reserved %i" % reserved print "-----" (listheader,listsize,streamheader,streamlist,streamsize,fcctype,fcchandler,shflags,wpriority,wlang,shinitialframes, scale,rate,start,length,shsuggestedbuffersize,quality,samplesize,rcframe) = struct.unpack("4sI4s4sI4s4sIIIIIIIIIIII",file[88:164]) print """listheader %s listsize %i streamheader: %s streamlist: %s streamsize %i fcctype %s fcchandler %s shflags %i wpriority %i wlang %i shinitialframes %i scale %i rate %i start %i length %i shsuggestedbuffersize %i quality %i samplesize %i rcframe %i -----""" % (listheader,listsize,streamheader,streamlist,streamsize,fcctype,fcchandler,shflags,wpriority,wlang,shinitialframes, scale,rate,start,length,shsuggestedbuffersize,quality,samplesize,rcframe) (junkhdr,junklen) = struct.unpack("4sI",file[330:338]) print """junkhdr: %s junklen %i""" % (junkhdr,junklen) print "-----" movicount = file.count("movi") print "movi block count: %i" % movicount moviloc = file.find("movi") print "movi block location: %i" % moviloc print "regexing..." avidata = file[moviloc+4:] avichunks = re.split("(00dc|01wb)",avidata)[1:] chunktype = avichunks[0::2] chunkdata = avichunks[1::2] for i in chunkdata[:10]: print len(i) print "%i chunk types, %i data blocks" % (len(chunktype), len(chunkdata)) streams = {} streams["00dc"] = [] streams["01wb"] = [] for i in xrange(len(chunktype)): stype = chunktype[i] sdata = chunkdata[i] streams[stype] += [sdata] for stream in streams.keys(): f = open("streams/%s" % stream,'w') print "writing streams/%s" % stream for block in streams[stream]: f.write(block[4:]) # ignore 4 byte size chunk f.close()