How, using Python script can I automate task like this: I have a Blender file with bunch of movie strips in the VSE (no sounds or music, all having transparent backgrounds, different lengths), a text and bunch of different still backgrounds. How to make Blender render each of video strips with each background, one by one as an mp4 to a specific directory, different then the one with the .blend file? If it'd be easier to import the videos and backgrounds from a folder instead keeping it in this .blend file that would work for me as well. Thank you.

  • $\begingroup$ It’s rather confusing how the files are actually arranged in your Sequencer, but as pertains to multiple file rendering: I previously wrote a script designed to split up chapters of a full movie in the video sequence editor using timeline markers, and name the files by the markers appropriately. It did this by just changing the main Blender file output each time, and then calling the render system. I don’t believe there is a system where you can output any file besides the main blender scene render output, unless it’s an image coming from the compositor, or a manually recorded file from Python $\endgroup$
    – TheLabCat
    Nov 18, 2021 at 22:31
  • $\begingroup$ Thanks for the comment. Looks like nobody can help on this task. $\endgroup$
    – Mzidare
    Nov 20, 2021 at 9:25

1 Answer 1


I've managed to answer my own question. Second approach, so importing files to Blender one by one and rendering it turned out easier to achieve (for me at least). The script below works as expected for Blender 2.81 (I don't think it works with 2.9). It's clunky, and I bet every coder makes a facepalm seeing it. It also gives an Error

"StructRNA of type MovieSequence has been removed"

but does what it's made for. So it's at least fast way to do it for anyone who needs that functionality.

import bpy
from bpy import context
import os
scene = context.scene

s = "/filepath/to_a/folderWith_Images/"
v = "/filepath/to_a/folderWith_videos/"

#this creates the list of all image files from folder s, without any folders names and other non files in the same folder
i = [ f for f in os.listdir(s) if os.path.isfile(os.path.join(s,f)) ]
#this creates the list of all videos from folder v
g = [ f for f in os.listdir(v) if os.path.isfile(os.path.join(v,f)) ]

#this creates strip with text overlayed over the videos
text = scene.sequence_editor.sequences.new_image("myText","/path/to_an/image_withText.png",8,1)
text.blend_type = 'ALPHA_OVER'

#defining a handler that will check if render job is finished and if yes, delete film strip
def znik_handler(scene):

#appending the handler to the scene    
bpy.app.handlers.render_complete.append( znik_handler )    

#loop that iterates through the image list and for each one renders all the videos with that image as the background
for x in i: 
    k = i.index(x)
    background = scene.sequence_editor.sequences.new_image(x,s+x, k+1, 1)
    for q in g:
        z = g.index(q)        
        film = scene.sequence_editor.sequences.new_movie(g[z], v+g[z],k+4, 1 )
        film.blend_type = 'ALPHA_OVER'
        film.use_translation = True
        film.transform.offset_y = 35
        text.frame_still_end = film.frame_duration
        background.frame_still_end = film.frame_duration
        scene.frame_end = film.frame_duration-1
        bpy.context.scene.render.filepath =  "/filepath/to_an/Output_folder/" + g[z].rsplit(".",1)[0]+"_" + x.rsplit(".")[0]+".mp4"    
        bpy.ops.render.render(animation = True, write_still = False, use_viewport = False)
  • $\begingroup$ I wrote similar script, and i am currently facing similar issue, with the difference i wrote an operator for it and it seems that whole operator gets removed as well on render_complete. Wonder if this is a bug or devs intentionally do not allow maintaining operator state for subsequent animation renders for some reason. It's indeed a weird one $\endgroup$
    – SourceCowD
    Mar 4, 2023 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .