Extract keyframes from audio without opening the composition

Moderators: Disciple, zlovatt

Post Reply
Posts: 3
Joined: June 28th, 2014, 10:16 am


I have this script, and part of the script deals with opening the comp in the viewer so that it can select the audio layer and create an audio null from it. I was wondering if there is a way to do this without opening the composition in the viewer, as this makes After Effects pop up over any active windows and makes the computer unusable for the duration the script is running.

I have other issues with my script but this is the most important one which will make the most difference.

Code: Select all

myComp.layers.add(sel[i]);                                                  //This adds the VO track the composition is based on to the composition
    myComp.openInViewer();                                                      //This opens the composition the loop is currently working on in the comp viewer. It is the reason AE constantly goes to the front of the screen and a highly inefficient part of the script, but it is the only way I know of extracting audio from the VO.
    myComp.layer(1).timeRemapEnabled = true;
    myComp.layer(1).selected = false;
    myComp.layer(3).selected = true;                                            //These two lines make sure that the audio layer is selected for the next step
    app.executeCommand(app.findMenuCommandId("Convert Audio to Keyframes"));    //This extracts audio data from voice over track in the form of keyframe data in a null layer
    myComp.layer(2).timeRemap.expression = "X = thisComp.layer(\"Audio Amplitude\").effect(\"Both Channels\")(\"Slider\"); linear(X,0,"+finalMaxVal+",0,"+tolerance+");"
    myComp.layer(3).position.expression = "comp(\""+bodyCompName+"\").layer(\"DogTransform\").transform.position";
    myComp.layer(3).scale.expression = "comp(\""+bodyCompName+"\").layer(\"DogTransform\").transform.scale"
    myComp.layer(3).rotation.expression = "comp(\""+bodyCompName+"\").layer(\"DogTransform\").transform.rotation"
    myComp.layer(3).selected = false;
    myComp.layer(1).selected = true;
    app.project.activeItem.layer(1).effect("Both Channels")(1).expression = "smooth("+smooth1+", "+smooth2+", time);";  //This adds a smooth expression to the null, this is the only way I've found to do this to date
    myComp.layer(2).outPoint = compDur;
Thank you,

Ted Mihu
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

The script has to open the comp because of this line:
app.executeCommand(app.findMenuCommandId("Convert Audio to Keyframes"));

This command is used to select the menu item for converting audio as there is no scripting specific command for this. But it requires the comp to be open as it would if you were selecting this menu command manually. So for this reason, I can't see any way around this.

There is the Trapcode Soundkeys plug-in which can also generate keyframes from audio. I don't know if its use can be scripted but that's the only alternative I can think of.

Post Reply