# Rendering video sequence editor by scripting

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?

• Check your permissions to write to that filepath, or if it even exists. The error is telling you it cannot open the file for writing. – batFINGER Feb 15 '18 at 11:42
• I feel so stupid. I had checked that the directory indeed existed and that I had the right to write in it, but it seems that by specifying 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! – G Viaud Feb 15 '18 at 12:04
• Hi. If you have an answer, please post it in the answer box below. – Ray Mairlot Feb 15 '18 at 12:37

bpy.data.scenes["Scene"].render.filepath = "/Users/***/Blender/mkv/"
bpy.data.scenes["Scene"].render.filepath = "/Users/***/Blender/mkv/" + str(n_strip) + ".mkv"