VSE sequencer 2.53 python scripting

Hello All,

Does someone has an example of image and sound strip creation in VSE of blender 2.53 ?
I have directories with thousands of images and sounds, and i would like to automate some creation tasks in the VSE.

looking at the documentation, i can access already created data:

editor=bpy.data.scenes[0].sequence_editor
seq=editor.sequences

but i still don’t know how to create new strips.

Any help will be greatly appreciated :smiley:
Benoit.

Hi, welcome :smiley:

what do you mean by " i would like to automate some creation tasks in the VSE" ?
what is you dev plan for your project ? Do you want to create a script for advanced workflow or just playing with code ?

let’s say i have 50 directories named dir1,dir2,…,dir50
in each directory i have 1000 images + 1 wav.

Instead of using the gui to add my 50 images strips + sound strips.
I want to have a script that will do the following:

  • take a directory name as input
  • create the 100 strips (images + sound) when i execute it.

Of course the only thing i am interested in is just the piece of code that will allow me to add image strip and sound strip.

Thanks,
Benoit

And to give even more details:
This is something i was doing with blender 2.49 with the following code:


scn=Blender.Scene.GetCurrent()
seq=scn.sequence
dir="toto"
currentPos=1
images = [i for i in sorted(set(os.listdir(dir)))]
seq_data=("//%s" % os.path.relpath(dir),images)
strip=seq.new(seq_data,currentPos,2)

Hope this make more sense :slight_smile:

thanks,
Benoit

we can imagine (also) that when importing video with sound track, it create automatically a “Meta strip” containing both video and audio ?

does it make sens ?
anyway, there is a lot of features that we dream to add to blender for a more efficient work, in practice !

Well it does make sense if you work with movie files.
But i use other piece of software that need images.
I have always found easier to work with images, and just create the movie file at the very end.

Sounds neat, would you also code a preset transition (with duration, cross or wipe) and perhaps run some audspace to pick out music beats to set the length of each clip. Thereby creating cuts to a beat.

Hi. I’m trying something similar in order to edit a short film into blender. But i want to create a lot of scenes (grouped into sequences) to node-grading each one and then compose in another timeline.

But still learning python basics…

Looking the documentation i found about bpy.ops.sequencer.image_strip_add()

and searching a lot in google i found a piece of code with something similar to this, and work for me:


bpy.ops.sequencer.image_strip_add(
directory = “//”,
files = [{“name”:“image.png”}],
frame_start=1,
frame_end=20)

but i dont know how to define more than one image…

The other operator bpy.ops.sequencer.movie_strip_add() also work this way, but in my workflow we need frames…


bpy.ops.sequencer.movie_strip_add(
filepath = “//”,
files = [{“name”:“rayos.avi”}],
frame_start=1)

Someone can explain how that group of files = [{“name”… works?

@titanium, keep us informed, please

Have you checked out this thread
http://blenderartists.org/forum/showthread.php?p=1705672#post1705672
as Michael W seems pretty knowledgeable about the VSE Python integration.

Finally i found a solution here (written 15 moths ago!!! :wink:

http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20656

But now it’s not exactly the same.

so, in order to import a sequence into the editor first we need to create a file dictionary, in the form [“name”:“file1”,“name”:“file2”,etc]. I use listdir function to get files from a directory. I also found how to define proxy files.


import bpy, os

dir="your_full_path_to_sequences_directory"  #not include files
dirproxy="full_path_to_proxy_file"                  #including proxy file

file=[]
for i in os.listdir(dir):
    frame={"name":i}
    file.append(frame)

bpy.ops.sequencer.image_strip_add( \
        directory = dir, \
        files = file, \
        frame_start=0, \
        channel=2, \
        filemode=9)

editor=bpy.data.scenes[0].sequence_editor
seq=editor.sequences
stripname=file[0].get("name")
mystrip=seq[stripname]

mystrip.use_proxy=True
mystrip.use_proxy_custom_file=True    
mystrip.proxy.filepath=dirproxy

Sure it’s a rought script but it works for me.

I’m actually creating jpeg sequences from canon5d files and 25% avi mjpeg proxy files with ffmpeg. Also you must set proxy to 25% in view settings.

This a old problem with context , I got an old error:

Traceback (most recent call last):  File "<blender_console>", line 6, in <module>
  File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules\bpy\ops.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.sequencer.image_strip_add.poll() failed, context is incorrect

Hi,
I get the same error message. Does anyone have an idea how to get around that?