我正在编写一个maya python脚本,将场景批量渲染为jpgs,然后使用ffmpeg将它们转换为mov。目前,该脚本将一串命令保存为bat文件,该文件工作正常,但我更喜欢从maya运行cmd.exe并执行命令列表而不先创建该bat。
我一直在阅读" subprocess.popen()"但是我无法弄清楚如何让它遍历每一行,运行该命令,然后在完成时移动到下一个,即:
1)运行maya render.exe&将场景另存为jpegs
2)ffmpeg jpgs to mov
我缩短了目录,但基本上是这样:
`C:\PROGRA~1\Autodesk\Maya2015\bin\Render.exe -r hw2 -s 100 -e 200 -of jpg -fnc 7 -x 1920 -y 1080 -rd
"C:\RENDER"
"C:\SCENE.ma" ffmpeg -y -r 25 -start_number 0100 -i C:\SCENE_%%04d.jpg C:\SCENE.mov
我怎么能这样做?
谢谢!
答案 0 :(得分:0)
first_process = subprocess.Popen(r'RenderCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
first_out,first_err = first_process.communicate()
first_exicode = first_process.returncode
print(first_out)
if str(first_exicode) != '0':
print(first_err)
second_process = subprocess.Popen(r'SecondCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
second_out,second_err = second_process.communicate()
second_exicode = second_process.returncode
print(second_out)
if str(second_exicode) != '0':
print(second_err)
third_process = subprocess.Popen(r'ConvertCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
third_out,third_err = third_process.communicate()
third_exicode = third_process.returncode
print(third_out)
if str(third_exicode) != '0':
print(third_err)
重要提示:
在执行每个Popen()期间,Maya的GUI将被冻结。这可能非常不方便,特别是如果要渲染很多帧。
我建议您将主要脚本中的渲染和转换调用分开以避免这种情况。
你可以这样做:
在您的主脚本中(您将调用Popen()
:
subprocess.Popen(r'mayapy.exe R:\paul\Trash\render_and_convert.py 50 100 150', False)
此命令不会冻结Maya的GUI。您可以将主脚本中的参数传递给render_and_convert.py
(文件路径,开始/结束帧等等)
render_and_convert.py:
import sys
import subprocess
import maya.standalone as std
std.initialize(name='python')
import maya.cmds as cmds
import maya.mel as mel
# store the arguments in variables
first_argument = sys.argv[1] # =50
second_argument = sys.argv[2] # =100
third_argument = sys.argv[3] # =150
first_process = subprocess.Popen(r'RenderCommand ' + first_argument + ' ' + second_argument,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
first_out,first_err = first_process.communicate()
first_exicode = first_process.returncode
print(first_out)
if str(first_exicode) != '0':
print(first_err)
second_process = subprocess.Popen(r'SecondCommandWithoutArgs', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
second_out,second_err = second_process.communicate()
second_exicode = second_process.returncode
print(second_out)
if str(second_exicode) != '0':
print(second_err)
third_process = subprocess.Popen(r'ConvertCommand ' + third_argument,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )
third_out,third_err = third_process.communicate()
third_exicode = third_process.returncode
print(third_out)
if str(third_exicode) != '0':
print(third_err)