A sample script that reads an ASC CDL from file (not using OCIO):
[code]# Sample script that applies an ASC CDL LUT to a bunch of frames, which are then encoded to a quicktime.
import Draft
import sys # To access commmand line arguments. Deadline sends script parameters as command line arguments.
from DraftParamParser import * # Functions to process command line arguments for Draft.
from CDLReader import * # ****** Functions to read ASC CDL from file and return a Draft.LUT
The argument name/types we’re expecting from the command line arguments or Deadline.
expectedTypes = dict()
expectedTypes[‘inFile’] = ‘’
expectedTypes[‘outFile’] = ‘’
expectedTypes[‘frameList’] = ‘’
#expectedTypes[‘asccdl’] = ‘’ # ****** uncomment this line if you want the asccdl parameter to be mandatory rather than optional
Parse the command line arguments.
params = ParseCommandLine( expectedTypes, sys.argv ) # params now contains a dictionary of the parameters initialized to values from the command line arguments.
inFilePattern = params[‘inFile’] # The pattern that the input files follow, for example frame_name_###.ext, where ### represents a three digit frame number.
frames = FrameRangeToFrames( params[‘frameList’] ) # Get a list of the individual frames we are to process
lut = GetASCCDLFromParams( params ) # ****** Get the ASC CDL, if a parameter named ‘asccdl’ is in the parameter list
Initialize the video encoder.
encoder = Draft.VideoEncoder( params[‘outFile’] )
Process each of the frames in the list of frames (including the first, which hasn’t yet been added to the encoder).
progressCounter = 0;
for currFrame in frames:
# Read in the frame.
currFile = ReplaceFilenameHashesWithNumber( inFilePattern, currFrame )
frame = Draft.Image.ReadFromFile( currFile )
if lut != None:
lut.Apply( frame ) # ****** apply the ASC CDL LUT to the frame
# Add the frame to the encoder.
encoder.EncodeNextFrame( frame )
progressCounter = progressCounter + 1
progress = progressCounter * 100 / len( frames )
print( "Progress: %i%%" % progress )
Finalize and save the resulting video.
encoder.FinalizeEncoding()[/code]
The CDL reader library:[code]import Draft
import xml.etree.ElementTree as ET
def ReadASCCDL( filename, allowHardFail=True ):
‘’‘Read an xml-formatted ASC CDL file, extract the slope, offset, power and
saturation, and return a Draft ASC CDL LUT.
Parameters:
filename: name of the ASC CDL file.
allowHardFail (optional): whether to raise an exception (default), or
warn and continue, if there are any problems with the ASC CDL file.
Returns: a Draft.LUT object, or None
‘’’
asccdllut = None
try:
tree = ET.parse( filename )
colorCorrectionNode = tree.find( 'ColorDecision' ).find( 'ColorCorrection' )
SOPNode = colorCorrectionNode.find( 'SOPNode' )
slope = SOPNode.find( 'Slope' ).text.split()
offset = SOPNode.find( 'Offset' ).text.split()
power = SOPNode.find( 'Power' ).text.split()
saturation = colorCorrectionNode.find( 'SatNode' ).find( 'Saturation' ).text
for i in range(0,3):
slope[i]=float(slope[i])
offset[i]=float(offset[i])
power[i]=float(power[i])
saturation = float(saturation)
asccdllut = Draft.LUT.CreateASCCDL(slope, offset, power, saturation)
except Exception as e:
if allowHardFail:
raise e
else:
print "WARNING: unable to process requested ASC CDL file, continuing without one. Error message: ", e
return asccdllut
def GetASCCDLFromParams( params, paramName=‘asccdl’, allowHardFail=True ):
‘’’ Check the parameter dictionary to see if an ASC CDL file has been
specified. If it has, attempt to read the file.
Parameters:
params: dictionary of parameters, one of which may contain the
filename of an ASC CDL LUT file.
paramName (optional): name of the parameter in params to look for,
defaults to ‘asccdl’.
allowHardFail (optional): whether to raise an exception (default), or
warn and continue, if there are any problems with the ASC CDL file.
Note: if the parameter is not in the dictionary, no exception is
raised.
Returns: a Draft.LUT object, or None
‘’’
asccdllut = None
if paramName in params:
asccdllut = ReadASCCDL( params[paramName], allowHardFail)
return asccdllut[/code]
I’ve attached both scripts for your ease of use.
basic_apply_cdl.zip (1.04 KB)
CDLReader.zip (940 Bytes)