Adding strips to the Blender Video Sequencer Editor

We can programmatically add various types of strips – video, audio, images, and image sequences to the Video Sequence Editor with the Blender Python API.

Images, audio, and video files are added to the desired Sequencer channels by creating new items in the “sequences” property collection of the “bpy.types.SequenceEditor” object.

Adding sound

To add a sound file to the Sequencer, we can use the “new_sound” function

with the following parameters:

name – the name of the strip being created

filepath – full path to source sound file

channel – number of the sequencer channel on which this strip should be placed

frame_start – frame number where the beginning of this strip should be placed

Adding a video

To add a video strip to the Sequencer, we can use the “new_movie” function

with the same parameters.

Adding an image

To add an image to the sequencer, use the “new_image” function

with the same parameters.

All of these functions return a pointer to the created strip.

Adding an Image Sequence

To create a strip with an image sequence – a set of sequential images, we need to use the “sequencer.image_strip_add” operator:

with:

directory – full path to the directory that contains the required set of images

files – list of dictionaries, each of which consists of a pair: “name” – file name with extension. In this list, through such dictionary pairs, we need to specify all the images that need to be loaded into the strip.

channel – number of the sequencer channel on which this strip should be placed

frame_start – frame number where the beginning of this strip should be placed

When using this operator, keep in mind that it is context sensitive. If we call it not from the context of the Sequence Editor area, but for example from a Text Editor area, we must specify the correct context for it, otherwise the operator will throw an error:

Operator bpy.ops.sequencer.image_strip_add.poll() failed, context is incorrect

Let’s override the context to the context of the Sequence Editor area and call the operator as follows:

Now we loaded all the required strips to the Video Sequence Editor.

0 0 votes
Article Rating
Subscribe
Notify of
guest

6 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Ajay
Ajay
2 months ago

obj_audio = bpy.context.scene.sequence_editor.sequences.new_sound(filepath=audio_file, name=”song”, channel=2, frame_start=1)
Error: Blender compiled without Audaspace support

Ajay
Ajay
2 months ago
Reply to  Ajay

I have tried bpy 4.1 and 4.0. Using Ubuntu. Installed bpy using pip. DO I need to install bpy differently to get the Audaspace support?

JOE MORRIS
JOE MORRIS
9 months ago

Can you make a post for everybody how to move sequencer clips and the timeline with python code based on say slider movement I have the code but you know I could give you but you know a very talented programmer wrote it so I don’t really 100% know how it works but then you know everybody would be able to do this if you could dissect my code let me know and I’ll go ahead and paste it