# ---------------------------------------------------------------- # checksequence # # Bernard Lebel # August 2004 # # checksequence.py is meant for a Python interpreter # (Python command line, Python IDLE, PythonWin and so on) # # # Description # checksequence's purpose is to detec missing frames in # rendered sequences, as well as drop frames (non-frames # and black frames), and this for a specified shot # by the user. # # # Installation # Put into C:\PythonXX\Lib # Remove the "_public" from the file name # # Usage # Launch a Python interpreter # Run: # import checksequence # Enter shot number # Enter first expected frame of sequence, without leading zeros # Enter last expected frame of sequence, without leading zeros # Read prints # # Note this script will work best if you always output # rendering to a central local. For the sRoot variable, # use that central location. # # Also note that this script is meant to analyse a single shot, # that is, with all the passes and such, but should be run several # times to analyse several shots. # # Thanks to Kent Johnson for the many suggestions # ---------------------------------------------------------------- # ----------------------------------------------------- # Import block import os # ----------------------------------------------------- print ' [[ CHECK SEQUENCE ]] ' print '' print '>>>>> IMPORTANT:' print 'Be sure to have clean directories before running the script.' # You may have to add few variables if you use a centralized output path. # For instance, one variable might be the sequence directory, # then the next one the shot directory, and so on. sSequence = raw_input( 'Shot: ' ) iStart = int( raw_input( 'Premier frame: ' ) ) iEnd = int( raw_input( 'Dernier frame: ' ) ) iCount = iEnd - iStart + 1 # Here is included an example of a folder you might wish the script to skip. # This example uses a directory meant for composite outputs #sComp = raw_input( '"comp" directory? [y/n]' ) # Define root search path # Again, if you use a centralized output path, insert that path before sSequence. sRoot = os.path.join( sSequence ) if not os.path.exists( sRoot ): print 'No shot found for the specified directory.' else: print '' print '>>>>> INFORMATIONS ABOUT THE SHOT:' print '1. Shot folder: ' + sRoot print '2. First frame: ' + str( iStart ) print '3. Last frame: ' + str( iEnd ) print '4. Expected number of frames: ' + str( iCount ) print '' print '>>>>> BEGINNING OF SHOT ANALYSIS' # Create emtpy list to store directories to be ignored aIgnoreList = [] print '' # Here you can then add the to be ignored folders you chose at the beginning # This is just an example #if sComp == 'n': # aIgnoreList.append( 'comp' ) # print '"comp" folders will be ignored.' # Iterate through root folder to collected folders for sDirPath, aDirName, oFiles in os.walk( sRoot, True, None ): # Iterate through ignore list for sIgnoreDir in aIgnoreList: # If the directories under the currently visited one are found in the ignore list.... if sIgnoreDir in aDirName: # ...ignore them! aDirName.remove( sIgnoreDir ) # Check if directory contains files if len( oFiles ) > 0: print '' print '_____ Analysis of >>>>>>>>>>>> ' + sDirPath # Create empty dictionary to store sequences aNames = {} # Iterate through files of current directory for oFile in oFiles: # Check the file size if os.path.getsize( os.path.join( sDirPath, oFile ) ) < 10855: print ' Drop or black: ' + oFile # Split file name into elements, and assign variables for each of them try: sName, sPad, sExt = oFile.split( '.' ) aNames.setdefault( sName, [] ).append( int( sPad ) ) except ValueError: pass # Iterate over each sequence for sName, aPad in aNames.items(): # Check if sequence has at least 33% of the required frame (otherwise it's considered unfinished) if len( aPad ) < round( iCount / 3 ): print ' Skipping sequence: "' + sName + '", less than 33% of expected frames found.' else: # Now create a virtual sequence of files for iFrame in range( iStart, iEnd + 1 ): # Check if the virtual frame number is found in the list of collected ones if not iFrame in aPad: # Not found! print ' Not found: ' + sName + '.' + str( iFrame ) # Script completed! print '' print '>>>>> END OF SHOT ANALYSIS'