Skip to content

Instantly share code, notes, and snippets.

@Postrediori
Last active July 11, 2024 06:39
Show Gist options
  • Save Postrediori/f535ce07b6e267cd4a226d0b85111f9e to your computer and use it in GitHub Desktop.
Save Postrediori/f535ce07b6e267cd4a226d0b85111f9e to your computer and use it in GitHub Desktop.
Blender 3D How-Tos

Blender 3D Tips&Tricks

How to automate blender video sequencer

Adda sequence of images to video timeline:

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
# start with 2nd image to omit adding the first one twice
for f in files[1:]:
    seq.elements.append(f)

# reverse if you want
seq.use_reverse_frames = False

# Make image sequence slower because by-default one image stands for one frame
# Extend the sequence 4 times by making it 25% of the original framerate
bpy.context.scene.sequence_editor.active_strip = seq
bpy.ops.sequencer.retiming_segment_speed_set(speed=25)

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment