View Full Version : python script to manipulate image sequences
luxwork 01-27-2009, 01:07 AM I have been looking for an easy solution to this for a while, perhaps someone can point me to some related code snippet. I would like to be able to recursively search directories looking for image sequences, and do things such as look for missing frames or abnormal frame sizes. It would also be nice to make moving and copying sequences as simple as single files.
Shake's file browser does a great job of showing sequences, it is adaptable to padded zeros and different naming formats (with or without . or _ etc)
So the main thing I am trying to learn now is to just list a directory's contents, detect the sequences, and make a list of files. Can anyone point me to a fragment that does that?
Also, are there any other forums or lists that have are actively discussing pipeline programming?
Thanks,
MD
|
|
greatPumpkin
01-27-2009, 04:22 AM
here's a directory walking snippet:
import os
# make a list to store the images that we find
images = []
# a simple example for finding iff's:
for root, dirs, files in os.walk('~/mydir'):
for file in [f for f in files if f.endswith(".iff")]:
# store the files in a list
images.append(file)
for beyond this you can use os.path.getsize to get the size of a file. Once you have the file size for every image in a sequence you can average their size and test the if individual members are below a certain percentage average? missing frames should be relatively straight forward once you're looping over every image.
if this is for a pipeline you can simplify much of this code if you force the user to use a standard padding convention, and standard paths for rendering rather then just walking an entire folder structure, and trying to account for every possible naming/numbering permutation.
For qualifying sequences i would look for code examples of regular expressions in python. google should have loads of results.
you can also take advantage of python's object oriented functionality by making a image sequence object that has attributes and methods that identify a sequence, then the objects themselves can have copy, move methods, and return missing/bad frames methods that should make handling them relatively easy/transparent
Hope that helps-
luxwork
01-27-2009, 05:35 PM
thanks for this
for the abnormal frames I would calculate an average of neighboring frames to find bad ones, since with rle files it can be hard to pick them out. Although, I have to say that I run into half frames infrequently with our switch to 64 bit
yes, enforcing the name conventions works, but there is always that runaway user..
I have been looking at the template feature of the string module, it looks like there may be some efficent techniques with that
you can also take advantage of python's object oriented functionality by making a image sequence object that has attributes and methods that identify a sequence, then the objects themselves can have copy, move methods, and return missing/bad frames methods that should make handling them relatively easy/transparent
Hope that helps-
That's a cool idea, and yes, it helps
MD
CGTalk Moderation
01-27-2009, 05:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.