I'm trying to render all individual strips that I have in the video sequence editor in separate files automatically.
I started this script:
import bpy
scene = bpy.context.scene
all_strips = list(sorted(scene.sequence_editor.sequences, key = lambda x: x.frame_final_start))
bpy.data.scenes["Scene"].render.filepath = "/Users/***/Blender/mkv/"
bpy.data.scenes["Scene"].render.image_settings.file_format = "FFMPEG"
for strip in all_strips:
if strip.type == "MOVIE":
start = strip.frame_final_start
end = strip.frame_final_end
bpy.context.scene.frame_start = start
bpy.context.scene.frame_end = end
bpy.ops.render.render(animation=True, use_viewport=True)
but I always get this error:
Traceback (most recent call last):
File "<blender_console>", line 7, in <module>
File "/Applications/Blender.app/Contents/Resources/2.79/scripts/modules/bpy/ops.py", line 189, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Could not open file for writing
Is there something wrong with bpy.ops.render.render(animation=True, use_viewport=True)
, with some context maybe?
bpy.data.scenes["Scene"].render.filepath = "/Users/***/Blender/mkv/"
Blender tries to create the file with the directory name (I thought Blender added automatically the filename with the start and end frames but whatever...). I changed it to:bpy.data.scenes["Scene"].render.filepath = "/Users/***/Blender/mkv/" + str(n_strip) + ".mkv"
inside the loop and it now works perfectly. Many thanks for the hint! $\endgroup$