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
1 2 3 4 5 6 |
sound_strip = bpy.context.scene.sequence_editor.sequences.new_sound( name='sound', filepath='_PATH_/sound.wav', channel=1, frame_start=1 ) |
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
1 2 3 4 5 6 |
video_strip = bpy.context.scene.sequence_editor.sequences.new_movie( name='video', filepath='_PATH_/video.mp4', channel=2, frame_start=1 ) |
with the same parameters.
Adding an image
To add an image to the sequencer, use the “new_image” function
1 2 3 4 5 6 |
image_strip = bpy.context.scene.sequence_editor.sequences.new_image( name='image', filepath='_PATH_/image.png', channel=3, frame_start=1 ) |
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:
1 2 3 4 5 6 |
bpy.ops.sequencer.image_strip_add( directory='_DIRECTORY_PATH_', files=[{"name": 'image001.png'}, {"name": 'image002.png'}, {"name": 'image003.png'}], frame_start=1, channel=4 ) |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
override_context = bpy.context.copy() area = [area for area in bpy.context.screen.areas if area.type == "SEQUENCE_EDITOR"][0] override_context['window'] = bpy.context.window override_context['screen'] = bpy.context.screen override_context['area'] = area override_context['region'] = area.regions[-1] override_context['scene'] = bpy.context.scene override_context['space_data'] = area.spaces.active bpy.ops.sequencer.image_strip_add( override_context, directory='_DIRECTORY_PATH_', files=[{"name": 'image001.png'}, {"name": 'image002.png'}, {"name": 'image003.png'}], frame_start=1, channel=4 ) |
Now we loaded all the required strips to the Video Sequence Editor.
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
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?
Unfortunately, I have no experience with Audaspace.
I think you need to compile its libraries to have its support, or compile your custom Blender build from its sources to have the Audaspace support.
Unfortunately the bpy pypi package is compiled without Audaspace. See https://projects.blender.org/blender/blender/issues/125007 and https://github.com/blender/blender/blob/a62f1dc6cc3a7860d74ae5666c6268f18eb8d2c8/build_files/cmake/config/bpy_module.cmake#L60
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
Ok, I will write this to my to-do list, and if I have some time I will see.
You can post your code here, or, you are welcome to register as an author and make a real post, I will moderate it, and then make it public.