# Copyright 2010 Jonathan Wong # python script to convert SWF files generated from tecplot to mpeg #requires swfextract import commands,sys,re,math def parse(filename): #check filename for .swf extension if not filename.find('.swf'): # not a comprehensive check return fileprefix = filename[0:filename.find('.swf')] commands.getstatusoutput("rm %s.mpeg" % (fileprefix,)) #open file status, output = commands.getstatusoutput("swfextract %s" % (filename,)) print output #find "JPEGs: ID(s)" slide_identifier = "PNGs: ID(s)" start=output.find(slide_identifier) slide_extract=[] if start: start += len(slide_identifier)+1 slide_end = output.find("[-f]",start) print start,slide_end slide_extract=output[start:slide_end-2].replace(" ","") # now extract all the data print "swfextract %s -P -p %s" % (filename,slide_extract) slides = slide_extract.split(",") digits = 1 + int(math.log10(int(slides[-1]))) for slide in slides: print "Processing frame: %d" % (int(int(slide)/2)+1,) print ("swfextract %%s -p %%s & mv output.png %s%%0%dd.png" % (fileprefix,digits,)) % (filename,slide,int(int(slide)/2)+1) status, output = commands.getstatusoutput(("swfextract %%s -p %%s && mv output.png %s%%0%dd.png" % (fileprefix,digits,)) % (filename,slide,int(int(slide)/2)+1)) status, output = commands.getstatusoutput("ffmpeg -f image2 -i %s%%04d.png -b 600k %s.mpeg && rm %s*.png" % (fileprefix,fileprefix,fileprefix)) return slide_extract if __name__=="__main__": slides=parse(sys.argv[1])