我正在使用 Processing IDE 为计算机视觉项目生成数百个短视频剪辑。现在,我正在使用 Python 创建一个.pde
文件并运行它。这看起来大致如下:
PATH = "/my/local/director/"
list_of_variables = [1, 2, etc.]
for i in list_of_variables:
naming = "p5_{:02d}_myfile".format(i)
os.mkdir(PATH + naming)
with open(PATH + naming + "/" + naming + ".pde", 'w') as pdefile:
pdefile.write("contents of file go here " + i ";\n")
pdefile.write("saveFrame(\"frames/######.tif\");\n")
subprocess.Popen(["processing-ide", "--sketch=" + PATH + naming, "--run"], stdout=subprocess.DEVNULL)
subprocess.call(["ffmpeg", "-i", PATH + naming + "/frames/%06d.tif", PATH + naming + "out.mp4"], stdout=subprocess.DEVNULL)
shutil.rmtree(PATH + naming + "/frames/")
每次执行代码时,Processing IDE 都会打开一个预览窗口来显示正在发生的事情。是否可以在执行步骤或.pde
文件创建中传递一个选项来阻止预览窗口显示。这需要很长时间,我希望这会加快速度。
注意:是的,我认为生成这些视频有更好的选择。回想起来,我应该OpenCV
在 Python 中使用来加快速度,但这不是这个问题的重点。