Whit python, In blender insert an EFFECT STRIP as WIPE in the VIDEO SEQUENCE EDITOR

In Blender using VIDEO SEQUENCE EDITOR you can insert still images (.jpg or png) as an IMAGE STRIP and create a carrousel.

In Blender using VIDEO SEQUENCE EDITOR you can insert still images (.jpg or png) as an IMAGE STRIP and create a carrousel

Between each image / IMAGE STRIP you can insert an EFFECT STRIP as WIPE to create a transition between images / IMAGE STRIP.

Between each image / IMAGE STRIP you can insert an EFFECT STRIP as WIPE to create a transition between images

The result:

enter image description here

I can insert images AS IMAGE STRIP into VIDEO SEQUENCE EDITOR using python.

Example:

I insert images AS IMAGE STRIP into VIDEO SEQUENCE EDITOR using this code:

import bpy, os

def importar():
    bpy.context.area.type = 'SEQUENCE_EDITOR'
    bpy.ops.sequencer.image_strip_add(directory="D:\\_webpages\\", files=[{"name": "000.jpg","name":"000.jpg" }], relative_path=True, show_multiview=False, frame_start=1, frame_end=289, channel=1);
    bpy.ops.sequencer.image_strip_add(directory="D:\\_webpages\\", files=[{"name": "001.jpg","name":"001.jpg" }], relative_path=True, show_multiview=False, frame_start=241, frame_end=529, channel=2);
    bpy.ops.sequencer.image_strip_add(directory="D:\\_webpages\\", files=[{"name": "002.jpg","name":"002.jpg" }], relative_path=True, show_multiview=False, frame_start=481, frame_end=770, channel=1);
    bpy.ops.sequencer.image_strip_add(directory="D:\\_webpages\\", files=[{"name": "003.jpg","name":"003.jpg" }], relative_path=True, show_multiview=False, frame_start=722, frame_end=1012, channel=2);
    bpy.ops.sequencer.image_strip_add(directory="D:\\_webpages\\", files=[{"name": "004.jpg","name":"004.jpg" }], relative_path=True, show_multiview=False, frame_start=964, frame_end=1255, channel=1);
    bpy.ops.sequencer.image_strip_add(directory="D:\\_webpages\\", files=[{"name": "005.jpg","name":"005.jpg" }], relative_path=True, show_multiview=False, frame_start=1207, frame_end=1499, channel=2);

importar()

The result: I insert several images each one in its alternating channel and in its own IMAGE STRIP.

There is an overlap between images / IMAGE STRIP to allow the transition.

Nowadays i want to create an EFFECT STRIP as WIPE using python.

Manually, to create an EFFECT STRIP as WIPE you have to:

a) select one image / IMAGE STRIP with the mouse

b) press the shift key and select another image / IMAGE STRIP with the mouse

c) add the wipe effect clicking on option ADD > EFFECT STRIP > WIPE

When you select the fist image / IMAGE STRIP, in the info window appear this code:

bpy.ops.sequencer.select(extend=False, linked_handle=False, left_right='NONE', linked_time=False)

When you select the second image / IMAGE STRIP, in the info window appear this code:

bpy.ops.sequencer.select(extend=True, linked_handle=False, left_right='NONE', linked_time=False)

When you add the wipe effect clicking on option ADD > EFFECT STRIP > WIPE, in the info window appear this code:

bpy.ops.sequencer.effect_strip_add(frame_start=71, frame_end=96, type='WIPE')

enter image description here

I have tried to create the EFFECT STRIP with python but I can not figure out how to select the image / IMAGE STRIP A, then select the image / IMAGE STRIP B and then create the EFFECT STRIP.

How can I select the image / IMAGE STRIP A and then select the image / IMAGE STRIP B with code?

Its possible to name the IMAGE STRIP and select it by name?

Nowadays I have created manually the EFFECT STRIP

Each EFFECT STRIP has its name

With python I can change the EFFECT STRIP properties, for example set the effect blur:

bpy.context.scene.sequence_editor.sequences_all["Wipe"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.001"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.002"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.003"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.004"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.005"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.006"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.007"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.008"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.009"].blur_width = 0.5
bpy.context.scene.sequence_editor.sequences_all["Wipe.010"].blur_width = 0.5

With python I can change the EFFECT STRIP properties, for example transition type, direction,

bpy.context.scene.sequence_editor.sequences_all["Wipe.001"].transition_type = 'IRIS';

bpy.context.scene.sequence_editor.sequences_all["Wipe.002"].transition_type = 'IRIS';
bpy.context.scene.sequence_editor.sequences_all["Wipe.002"].direction = 'IN';

bpy.context.scene.sequence_editor.sequences_all["Wipe.003"].transition_type = 'SINGLE';

bpy.context.scene.sequence_editor.sequences_all["Wipe.004"].transition_type = 'SINGLE';
bpy.context.scene.sequence_editor.sequences_all["Wipe.004"].direction = 'IN';

bpy.context.scene.sequence_editor.sequences_all["Wipe.005"].transition_type = 'SINGLE';
bpy.context.scene.sequence_editor.sequences_all["Wipe.005"].angle = 0.785398;

bpy.context.scene.sequence_editor.sequences_all["Wipe.006"].transition_type = 'SINGLE';
bpy.context.scene.sequence_editor.sequences_all["Wipe.006"].direction = 'IN';
bpy.context.scene.sequence_editor.sequences_all["Wipe.006"].angle = 0.785398;

bpy.context.scene.sequence_editor.sequences_all["Wipe.007"].transition_type = 'SINGLE';
bpy.context.scene.sequence_editor.sequences_all["Wipe.007"].angle = 1.5708;

bpy.context.scene.sequence_editor.sequences_all["Wipe.008"].transition_type = 'SINGLE';
bpy.context.scene.sequence_editor.sequences_all["Wipe.008"].direction = 'IN';
bpy.context.scene.sequence_editor.sequences_all["Wipe.008"].angle = 1.5708;

bpy.context.scene.sequence_editor.sequences_all["Wipe.009"].transition_type = 'DOUBLE';

bpy.context.scene.sequence_editor.sequences_all["Wipe.010"].transition_type = 'DOUBLE';
bpy.context.scene.sequence_editor.sequences_all["Wipe.010"].direction = 'IN';

Upvotes: 1

Views: 1140

Answers (3)

Blender 2.8 CODE UPDATE

The previous code wont work in Blender 2.8

The code needs an update, this is the modified code working in blender 2.8

A working example, just copy and paste to test on python console (change image real paths and names):

import bpy, os

from bpy import context

scene = context.scene

def importar():
    scene.sequence_editor_create()
    bpy.context.area.type = 'SEQUENCE_EDITOR'
    #
    # import images as image strip
    #
    s1= scene.sequence_editor.sequences.new_image('p01', '/real_path_to_file/000.jpg',1,1);
    s2= scene.sequence_editor.sequences.new_image('p02', '/real_path_to_file/001.jpg',2,241);
    s3= scene.sequence_editor.sequences.new_image('p03', '/real_path_to_file/002.jpg',1,481);
    s4= scene.sequence_editor.sequences.new_image('p04', '/real_path_to_file/003.jpg',2,722);
    s5= scene.sequence_editor.sequences.new_image('p05', '/real_path_to_file/004.jpg',1,964);
    #
    # set duration for each strip
    #
    s1.frame_final_duration = 288;
    s2.frame_final_duration = 288;
    s3.frame_final_duration = 288;
    s4.frame_final_duration = 288;
    s5.frame_final_duration = 288;
    #
    # create wipe effect
    #
    w1= scene.sequence_editor.sequences.new_effect('wipe01', 'WIPE', 3,s2.frame_start,seq1=s1, seq2=s2);
    w2= scene.sequence_editor.sequences.new_effect('wipe02', 'WIPE', 3,s3.frame_start,seq1=s2, seq2=s3);
    w3= scene.sequence_editor.sequences.new_effect('wipe03', 'WIPE', 3,s4.frame_start,seq1=s3, seq2=s4);
    w4= scene.sequence_editor.sequences.new_effect('wipe04', 'WIPE', 3,s5.frame_start,seq1=s4, seq2=s5);
    #
    # set blur property for wipe effect
    #
    bpy.context.scene.sequence_editor.sequences_all["wipe01"].blur_width = 0.5;
    bpy.context.scene.sequence_editor.sequences_all["wipe02"].blur_width = 0.5;
    bpy.context.scene.sequence_editor.sequences_all["wipe03"].blur_width = 0.5;
    bpy.context.scene.sequence_editor.sequences_all["wipe04"].blur_width = 0.5;    
    #
    # set properties for wipe effects
    #
    bpy.context.scene.sequence_editor.sequences_all["wipe01"].transition_type = 'SINGLE';
    bpy.context.scene.sequence_editor.sequences_all["wipe01"].direction = 'IN';
    bpy.context.scene.sequence_editor.sequences_all["wipe02"].transition_type = 'SINGLE';
    bpy.context.scene.sequence_editor.sequences_all["wipe02"].angle = 0.785398;
    bpy.context.scene.sequence_editor.sequences_all["wipe03"].transition_type = 'SINGLE';
    bpy.context.scene.sequence_editor.sequences_all["wipe03"].direction = 'IN';
    bpy.context.scene.sequence_editor.sequences_all["wipe03"].angle = 0.785398;
    bpy.context.scene.sequence_editor.sequences_all["wipe04"].transition_type = 'SINGLE';
    bpy.context.scene.sequence_editor.sequences_all["wipe04"].angle = 1.5708;

importar()

In Blender 2.8 it is not necesarry include frame end parameter with the method: scene.sequence_editor.sequences.new_effect

To clarify some methods this code adds manually each image strip, wipe effect and effect properties.

Obviously with python you can automate and add all png or jpgs files in a directory... automate the wipe effect creation... automate or randomize each wipe effect properties.

Upvotes: 0

Thank you very much sambler.

That work very well!

A working example, just copy and paste to test on python console (change image real paths and names)

import bpy, os

from bpy import context

scene = context.scene

def importar():
    scene.sequence_editor_create()
    bpy.context.area.type = 'SEQUENCE_EDITOR'
    #
    # import images as image strip
    #
    s1= scene.sequence_editor.sequences.new_image('p01', '/real_path_to_file/000.jpg',1,1);
    s2= scene.sequence_editor.sequences.new_image('p02', '/real_path_to_file/001.jpg',2,241);
    s3= scene.sequence_editor.sequences.new_image('p03', '/real_path_to_file/002.jpg',1,481);
    s4= scene.sequence_editor.sequences.new_image('p04', '/real_path_to_file/003.jpg',2,722);
    s5= scene.sequence_editor.sequences.new_image('p05', '/real_path_to_file/004.jpg',1,964);
    #
    # set duration for each strip
    #
    s1.frame_final_duration = 288;
    s2.frame_final_duration = 288;
    s3.frame_final_duration = 288;
    s4.frame_final_duration = 288;
    s5.frame_final_duration = 288;
    #
    # create wipe effect
    #
    w1= scene.sequence_editor.sequences.new_effect('wipe01', 'WIPE', 3,s2.frame_start,s1.frame_final_end,seq1=s1, seq2=s2);
    w2= scene.sequence_editor.sequences.new_effect('wipe02', 'WIPE', 3,s3.frame_start,s2.frame_final_end,seq1=s2, seq2=s3);
    w3= scene.sequence_editor.sequences.new_effect('wipe03', 'WIPE', 3,s4.frame_start,s3.frame_final_end,seq1=s3, seq2=s4);
    w4= scene.sequence_editor.sequences.new_effect('wipe04', 'WIPE', 3,s5.frame_start,s4.frame_final_end,seq1=s4, seq2=s5);
    #
    # set blur property for wipe effect
    #
    bpy.context.scene.sequence_editor.sequences_all["wipe01"].blur_width = 0.5;
    bpy.context.scene.sequence_editor.sequences_all["wipe02"].blur_width = 0.5;
    bpy.context.scene.sequence_editor.sequences_all["wipe03"].blur_width = 0.5;
    bpy.context.scene.sequence_editor.sequences_all["wipe04"].blur_width = 0.5;    
    #
    # set properties for wipe effects
    #
    bpy.context.scene.sequence_editor.sequences_all["wipe01"].transition_type = 'SINGLE';
    bpy.context.scene.sequence_editor.sequences_all["wipe01"].direction = 'IN';
    bpy.context.scene.sequence_editor.sequences_all["wipe02"].transition_type = 'SINGLE';
    bpy.context.scene.sequence_editor.sequences_all["wipe02"].angle = 0.785398;
    bpy.context.scene.sequence_editor.sequences_all["wipe03"].transition_type = 'SINGLE';
    bpy.context.scene.sequence_editor.sequences_all["wipe03"].direction = 'IN';
    bpy.context.scene.sequence_editor.sequences_all["wipe03"].angle = 0.785398;
    bpy.context.scene.sequence_editor.sequences_all["wipe04"].transition_type = 'SINGLE';
    bpy.context.scene.sequence_editor.sequences_all["wipe04"].angle = 1.5708;

importar()

To clarify some methods this code adds manually each image strip, wipe effect and effect properties.

Obviously with python you can automate and add all png or jpgs files in a directory... automate the wipe effect creation... automate or randomize each wipe effect properties.

Upvotes: 0

sambler
sambler

Reputation: 7079

Rather than using Blender's operators, it is recommended to access the data directly in scripts, apart from performance considerations it is often easier and clearer to work with the data.

You can find the VSE's sequence list in the scene properties

import bpy
seqs = bpy.context.scene.sequence_editor.sequences

You can then add new sequence strips to that list and adjust any strip properties -

s1 = seqs.new_image('img001', '//renders/img001.jpg', 1, 1)
s1.frame_final_duration = 288
s2 = seqs.new_image('img002', '//renders/img002.jpg', 2, 241)
s2.frame_final_duration = 288

Then using the reference to the two strips, create a wipe effect

w = seqs.new_effect('wipe01', 'WIPE', 3,
            s2.frame_start, s1.frame_final_end, seq1=s1, seq2=s2)
w.transition_type = 'IRIS'

Then starting with the second strip, add another strip and a wipe between them

s1 = s2
s2 = seqs.new_image('img003', '//renders/img003.jpg', 1, 481)
s2.frame_final_duration = 288
w = seqs.new_effect('wipe02', 'WIPE', 3,
            s2.frame_start, s1.frame_final_end, seq1=s1, seq2=s2)
w.transition_type = 'SINGLE'

s1 = s2
s2 = seqs.new_image('img004', '//renders/img004.jpg', 2, 722)
s2.frame_final_duration = 288
w = seqs.new_effect('wipe03', 'WIPE', 3,
            s2.frame_start, s1.frame_final_end, seq1=s1, seq2=s2)
w.transition_type = 'DOUBLE'

Upvotes: 3

Related Questions