Ubuntu 12.04 has moved to avconv from ffmpeg and my previous python script to execute a shell script on Nuke’s afterRender callback needed to be updated appropriately.
Additional changes:
- The function now takes an arg ‘dnxhd’ to output a movie using the avid codec instead of the default x264.
- the renderSlug configuration option has been added
- when false: the movie start frame = the nuke project start frame*
- when true: the movie start frame = 0
* Note: You always have to render from frame 0 out of Nuke regardless of the project start frame (avconv image sequences always start at 0).
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# Send rendered image sequence to shell avconv call def sendToAvconv(codec = 'x264'): # Configuration renderSlug = False vcodec = { 'x264' : 'libx264 -pre baseline', 'dnxhd' : 'dnxhd -b 36M', } extension = '.mov' # set some variables fps = nuke.root().knob('fps').value() firstFrame = nuke.root().knob('first_frame').value() ss = 0 if renderSlug == True else secondsToStr(firstFrame/fps) # grabs the write node's file value and makes sure the path uses printf style filenames imgSeqPath = nukescripts.replaceHashes(nuke.filename(nuke.thisNode())) # generate mov path base, ext = os.path.splitext(os.path.basename(imgSeqPath)) movPath = os.path.dirname(os.path.dirname(imgSeqPath)) + '/' + re.sub('\.?%0\d+d$', '', base) + extension # make shell command enc = 'avconv -y -r %s -i \'%s\' -an -ss %s -vcodec %s -threads 0 \'%s\'' % (fps, imgSeqPath, ss, vcodec[codec], movPath) subprocess.Popen(shlex.split(enc), stdout=subprocess.PIPE, stderr=subprocess.PIPE) # returns HH:MM:SS.SSS formatted string # http://code.activestate.com/recipes/511486/ def secondsToStr(t): rediv = lambda ll,b : list(divmod(ll[0],b)) + ll[1:] return "%02d:%02d:%02d.%03d" % tuple(reduce(rediv,[[t*1000,],1000,60,60])) |

