9
$\begingroup$

Is it possible to automate the sequencer so that each time I render an animation into image files in a folder, the newly rendered image files would be inputted into the sequencer in a specific arrangement or something like this?:

  1. Load images 1-300 and place in sequencer
  2. Load images 1-300, again, and place after first image sequence
  3. Apply backwards effect to the second image sequence

If not an option in blender, is there a way to create a script to do this? Often I will rerender the same animation with a different setting or something, but every time I have to manually apply what was described above. I'm not necessarily asking for a solution specified to this example, but for all examples like this. Is there something that would work to automate this process?

Any help is appreciated. If what I am describing is unclear I can further describe it.

$\endgroup$
12
$\begingroup$

Yes, blenders sequencer has full Python API access so it can be used to do quite advanced video editing both from the UI or in background mode (headless).

import os

from bpy import context
scene = context.scene

path = "/my_path/to/images"
files = os.listdir(path)
files.sort()

# create the sequencer data
scene.sequence_editor_create()

seq = scene.sequence_editor.sequences.new_image(
        name="MyStrip",
        filepath=os.path.join(path, files[0]),
        channel=1, frame_start=1)

# add the rest of the images.
for f in files:
    seq.elements.append(f)

# reverse if you want
seq.use_reverse_frames = False

# You may want to render the result:

render = scene.render
scene.frame_start = 1
scene.frame_end = 1 + len(files)

render.resolution_x = 1280
render.resolution_y = 720
render.fps = 25

render.image_settings.file_format = 'FFMPEG'
render.ffmpeg.format = 'MPEG4'
render.ffmpeg.codec = 'H264'

render.ffmpeg.constant_rate_factor = 'HIGH'
render.ffmpeg.ffmpeg_preset = 'BEST'

bpy.ops.render.render(animation=True)

The rest I'm sure you can work out as you may want to tweak encoding, frame rate... etc.

$\endgroup$
2
  • $\begingroup$ You've kinda left out the most important part: How to sequence that strip into a video. $\endgroup$ – Robin De Schepper Sep 21 '20 at 14:08
  • $\begingroup$ This could be fairly large depending on what codecs, format etc you want to set. Added brief block for rendering results. $\endgroup$ – ideasman42 Sep 21 '20 at 23:52
4
$\begingroup$

Yes, It is quite possible (ideasman42 already gave an example of the Sequencer API usage).

You can also setup the automation logic that will create/update your sequencer using a render complete handler. In your addon, You can register the sequencer setup handler to run after render completes.

@bpy.app.handlers.persistent
def process_in_sequencer(self, context):
    <logic goes here>

bpy.app.handlers.render_complete.append(process_in_sequencer)
$\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.