2
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – batFINGER Feb 15 '18 at 11:42
  • $\begingroup$ 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! $\endgroup$ – G Viaud Feb 15 '18 at 12:04
  • 1
    $\begingroup$ Hi. If you have an answer, please post it in the answer box below. $\endgroup$ – Ray Mairlot Feb 15 '18 at 12:37
2
$\begingroup$

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 actually thought that Blender added automatically the filename with the start and end frames...). 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.

Kudos to batFINGER for the hint.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.