Executing external programs via RF-Python

Discussion about scripting with Python
User avatar
jalixko
Posts: 72
Joined: Tue Jan 02, 2007 1:11 pm

Executing external programs via RF-Python

Postby jalixko » Tue Nov 13, 2012 10:06 am

Hi all!
I am working this days in a script to generate previews using external converter image sequence to mov.
I am using two opensource applications such as ffmpeg and djv which are capable to convert almost any format into mov h264.
So the process I am trying to run is generate a preview an execute one of the external applications above described from RF-Python.
This is my code:

Code: Select all

import os
import string
##Contruct paths

fileName = scene.getFileName()
(shortname, extension) = os.path.splitext(fileName)
root = scene.getRootPath()
vid = scene.getExportResourcePath(5)
frame = scene.getExportResourcePath(6)
(scenedir, vidPath) = vid.split("$(SCENEDIR)")
(scnedir, fraPath) = frame.split("$(SCENEDIR)")
videoPath = str(root) + str(vidPath) + "/"
framePath = str(root) + str(fraPath) + "/"
endframe = scene.getMaxFrames()
endframe = string.zfill(str(endframe), 4)
scene.message(str(endframe))

##scene.message(str(videoPath))
##scene.message(str(framePath))

##video preview generation

scene.videoPreview(str(videoPath), str(framePath), 1024, 576, False, True, 0, 50, False, 2)
program = "C:\\Program Files (x86)\\djv-0.9.0\\bin\\djv_convert.exe "
command = str(program) + str(framePath) + "frame_0000-" + str(endframe) + ".png " + str(videoPath) + shortname + ".mov"
scene.message(str(command))
os.system(command)
openOutput = str(videoPath) + shortname + ".mov"
os.system(openOutput)

The problem now is the command is not execute although the rf shows as "done".
Any thoughts?


User avatar
jalixko
Posts: 72
Joined: Tue Jan 02, 2007 1:11 pm

Re: Executing external programs via RF-Python

Postby jalixko » Wed Nov 14, 2012 11:53 am

Solved!!! :D
Could anyone test it?

Code: Select all

def main():
   ############################################################
   # Batch script to create previews in mov format and compressed in Windows.
   # How it works:
   # Simply select the window and execute
   # Need at least DJV: http://djv.sourceforge.net/ or Ffmpeg: http://ffmpeg.org/
   # When they were installed change "program" variable paths for your installation paths
        # Don´t forget use double back slashes
   ###########################################################
   # Name :   QuickTime Preview
   # Icon :    yes
   # Shortcut :    No
   # Toolbar :    No
   # Author :    Jorge Medina Alix
   # Date :    14 Novbiembre 2012
   # Version :    1.0
   ##################################
   import os
   import string
   import commands
   import subprocess
   
   #Contruct paths
   
   fileName = scene.getFileName()
   (shortname, extension) = os.path.splitext(fileName)
   root = scene.getRootPath()
   vid = scene.getExportResourcePath(5)
   frame = scene.getExportResourcePath(6)
   (scenedir, vidPath) = vid.split("$(SCENEDIR)")
   (scnedir, fraPath) = frame.split("$(SCENEDIR)")
   videoPath = str(root) + str(vidPath) + "/"
   framePath = str(root) + str(fraPath) + "/"
   endframe = scene.getMaxFrames()
   ceroendframe = string.zfill(str(endframe), 5)
   
   #Menu
   form = GUIFormDialog.new()
   form.setTitle("QuickTime preview")
   form.addStringField( "Name preview",shortname )
   options = [ "ffmpeg", "djv" ]
   form.addListField( "Converter", options, 0 )
   form.addIntField( "Resolution X", 600 )
   form.addIntField( "Resolution Y", 338 )
   if ( form.show() == GUI_DIALOG_ACCEPTED ):
      converter = options[int(form.getFieldValue( "Converter") )]
      resX = form.getFieldValue( "Resolution X")
      resY = form.getFieldValue( "Resolution Y")
      newfilename = form.getFieldValue( "Name preview")
      scene.videoPreview(str(videoPath), str(framePath), int(resX), int(resY), False, True, 0, int(endframe), False, 2)
      scene.message(str("<font color=orange>Converting preview, this task could take several minutues depending on length of simulation...............</font>"))
      if converter == "ffmpeg":
         program = "H:\\soft\\Downloads\\ffmpeg-20120726-git-236ecc3-win64-static\\bin\\ffmpeg.exe "
         command = str(program) + "-f image2 -i  " + str(framePath) + "frame_"+ "%%" + "05d.png -vcodec copy -vbsf h264_mp4toannexb " + str(videoPath) + newfilename + ".mov"
      elif converter == "djv":
         program = "H:\\soft\\Downloads\\djv-0.8.3-pre2_winxp-x86\\bin\\djv_convert.exe "
         command = str(program) + "-speed " + str(scene.getFps()) + " "  + str(framePath) + "frame_00000-" + str(ceroendframe) + ".png " + str(videoPath) + newfilename + ".mov"
            
      #Create tmp bat
      #scene.message(str(command))
      infile=open("c:\\converttmp.bat", "w")   #Opens the file
      infile.write(str(command))         #Writes the desired contents to the file
      infile.close()               #Closes the file
      
      #Executes bat file
      
      os.system("c:\\converttmp.bat")
      os.remove("c:\\converttmp.bat")
      
      #Open Preview
      
      os.startfile(str(videoPath) + newfilename + ".mov")
if __name__ == "RealFlow":
   main()


User avatar
jalixko
Posts: 72
Joined: Tue Jan 02, 2007 1:11 pm

Re: Executing external programs via RF-Python

Postby jalixko » Tue Nov 20, 2012 7:48 am

Solved!!!


Return to “Python-Scripting”

Who is online

Users browsing this forum: Google [Bot] and 1 guest