Jun 14

Blender: adding Effects via the Python API

Category: Linux,multimedia   — Published by tengo on June 14, 2011 at 11:45 am

This article is an unfinished sketch!

Automating tasks in in Blender's NLE, the Sequence Editor, via the Python API can be a tricky task. Most I've achieved so far I managed by trial and error.

For example, I've found the docs to be quite unclear on how to add Video Effects via the API, so the only help was to have a look at the code. The relevant part from sceneSequence.c:

static PyObject *M_Sequence_BlendModesDict(void)

{

 PyObject *M = PyConstant_New();	if (M)

 {

 	BPy_constant *d = (BPy_constant *) M;

 	PyConstant_Insert(d, "CROSS", PyInt_FromLong(SEQ_CROSS));

 	PyConstant_Insert(d, "ADD", PyInt_FromLong(SEQ_ADD));

 	PyConstant_Insert(d, "SUBTRACT", PyInt_FromLong(SEQ_SUB));

 	PyConstant_Insert(d, "ALPHAOVER", PyInt_FromLong(SEQ_ALPHAOVER));

 	PyConstant_Insert(d, "ALPHAUNDER", PyInt_FromLong(SEQ_ALPHAUNDER));

 	PyConstant_Insert(d, "GAMMACROSS", PyInt_FromLong(SEQ_GAMCROSS));

 	PyConstant_Insert(d, "MULTIPLY", PyInt_FromLong(SEQ_MUL));

 	PyConstant_Insert(d, "OVERDROP", PyInt_FromLong(SEQ_OVERDROP));

 	PyConstant_Insert(d, "PLUGIN", PyInt_FromLong(SEQ_PLUGIN));

 	PyConstant_Insert(d, "WIPE", PyInt_FromLong(SEQ_WIPE));

 	PyConstant_Insert(d, "GLOW", PyInt_FromLong(SEQ_GLOW));

 	PyConstant_Insert(d, "TRANSFORM", PyInt_FromLong(SEQ_TRANSFORM));

 	PyConstant_Insert(d, "COLOR", PyInt_FromLong(SEQ_COLOR));

 	PyConstant_Insert(d, "SPEED", PyInt_FromLong(SEQ_SPEED));

 }

 return M;

}

Effects are (not quite user friendly) identified by integers (numbers), ascending in the order of the above subroutine, starting with CROSS at 8. So adding the ALPHAOVER overimpose effect would need:

seq_data = (11, <the first video strip>, <the second video strip>)

addeffect = seq.new(seq_data, <start frame>, <track number>)

or to make it even clearer, to use the ADD overimpose method:

seq_data = (9, <the first video strip>, <the second video strip>)

addeffect = seq.new(seq_data, <start frame>, <track number>)

To illustrate this:
14 = MULTIPLY
15 = OVERDROP
16 = PLUGIN (crash)
17 = WIPE (crash)
18 = GLOW (crash)
19 = TRANSFORM (crash)
20 = crash
21 = crash

Some effects expect only one video strip to be connected with, other, like overimpose/wipes etc. two or more.As the source states: "effect stripts expected an effect type int and 1 to 3 sequence strips".

Hint: What exactly each effect expects can be found out by omitting everything after the effect integer and letting blender spit out the error, else blender often just silently crashes. Still, the "No in/out points set." error wasn't so helpful in most cases.

Related:
Sequencer Python API - can't do movie strips (on how to add COLOR or MOVIE strips to tracks)