写了一个hiero检查任务渲染结果的脚本

时间:2022-03-05 15:04:43

基本思路是写了一个时间判断函数(postSequence_check)来对比transcode任务提交时间和目标文件夹内文件的修改时间来确定渲染是否成功执行,然后通过Hiero提供的postSequence钩子函数将时间判断函数(postSequence_check)注入进Hiero。

用法很简单,保存为一个脚本,并在__init__中引用即可。
Talk is cheap,show you the code:
###################################################################################################################################################################
import hiero.core,hiero.exporters
import sys
import os,datetime
import time
 
#GLOBAL_NAMELIST=[]

def updateItem_new (self, originalItem, localtime):
    #print sys._getframe().f_code.co_name

global GLOBAL_LOCALTIME,GLOBAL_CLASS_TYPE
    GLOBAL_LOCALTIME = time.mktime(localtime)
    GLOBAL_CLASS_TYPE = self

"""updateItem - This is called by the processor prior to taskStart, crucially on the main thread.\n
      This gives the task an opportunity to modify the original item on the main thread, rather than the clone."""
    #if isinstance(self._item, (Sequence,TrackItem)):
    #if isinstance(self._item, Clip):

timestamp = self.timeStampString(localtime)
    tag = hiero.core.Tag("Transcode " + timestamp, "icons:Nuke.png")
    tag.metadata().setValue("tag.path", self.resolvedExportPath())
    tag.metadata().setValue("tag.localtime", str(localtime))
    # Right now dont add the time to the metadata
    # We would rather store the integer time than the stringified time stamp
    #tag.setValue("time", timestamp)

# No point in adding script path if we're not planning on keeping the script
    if self._preset.properties()["keepNukeScript"]:
      tag.metadata().setValue("tag.script", self._scriptfile)

start, end = self.outputRange()
    tag.metadata().setValue("tag.startframe", str(start))
    tag.metadata().setValue("tag.duration", str(end-start+1))
    
    frameoffset = self._startFrame if self._startFrame else 0
    if hiero.core.isVideoFileExtension(os.path.splitext(self.resolvedExportPath())[1].lower()):
      frameoffset = 0
    tag.metadata().setValue("tag.frameoffset", str(frameoffset))
    
    if self._cutHandles:
      tag.metadata().setValue("tag.handles", str(self._cutHandles))

self._tag_guid = tag.guid()

originalItem.addTag(tag)

# The guid of the tag attached to the trackItem is different from the tag instace we created
    # Get the last tag in the list and store its guid
    self._tag_guid = originalItem.tags()[-1].guid()
    
hiero.exporters.FnTranscodeExporter.TranscodeExporter.updateItem = updateItem_new

######################################################################################################
######################################################################################################
######################################################################################################

def postSequence_check(self):

#print sys._getframe().f_code.co_name
    
    #print self.__class__

#print self._filebase

if isinstance(self,hiero.exporters.FnTranscodeExporter.TranscodeExporter):
        #print "yeah!"
        #print self._root
        #print self._shotPath
        #print self._filebase
        #print self._version
        #print self._track
        #print self.outputRange()
        #print self.properties()
        #print initDictionary

#GLOBAL_NAMELIST.append(self._filebase)

base_dir = self._root
        base_dir = "/".join(base_dir.split('/')[0:-1])
        print self._filebase
        list = []
        timestamplist = []
        list = os.listdir(base_dir)

if len(list) > 0:
            for i in range(0, len(list)):  
                path = os.path.join(base_dir,list[i])  
                if os.path.isfile(path):  
                    path = os.path.join(base_dir, list[i])  
                    if os.path.isdir(path):  
                        continue  
                    timestamp = os.path.getmtime(path)  
                    timestamplist.append(timestamp)
        
            #print GLOBAL_LOCALTIME,min(timestamplist)

if GLOBAL_LOCALTIME > min(timestamplist):
                print "(VHQ) This transcode task has some problem:" + self._filebase
            else:
                print '(VHQ) This transcode task is OK!'
        else:
            print "(VHQ) This transcode task has some problem:" + self._filebase
    else:
        base_dir = self._filebase
        #base_dir = "/".join(base_dir.split('/')[0:-1])
        print base_dir
        print str(self.__class__).strip('<').strip('>').strip("'").split('.')[-1] + ' is not transcode render task!'

hiero.core.FnExporterBase.TaskBase.postSequence = postSequence_check