There have been several times in the past where I wanted to sync audio and video together but did not know how. Key framing was not the answer (too cumbersome and LOOOOOONG). Trapcode Soundkeys works well; however, sometimes I want to have movement at specific words or notes that Soundkeys did not pick up consistently. Plus it is not free. Then I saw a little expression Dan Ebberts setup for someone that used layer markers to trigger a timeremap. I looked at this expression and was amazed at how simple it was. So I decided to rip it apart and figure out how to do other things with it.
Other people out there might already have this stuff done but I thought that since I did it and people sometimes have these questions, I might as well put it all together for everyone. When I started compiling all of the different expressions, I wanted to cover as much ground as possible and make many different expression sets. Yes some of these are very similar and might not be useful to everyone but I wanted to cover as much as possible. Some expression sets have a value from 0 to 1 between markers while others step by one at each marker. By adding, subtracting, multiplying and dividing the different sets together you can get many different outputs (we will some of this later).
First of all I am not a programmer. I repeat I am not a programmer. This article is not to show that I found the best way to code these expressions. It is to let others see how easy and versatile the layer markers can be in syncing video to audio. Hopefully that after seeing the information below, you can better understand why the code works so you can better decide how you can best use it for yourself.
|
The different code arrangements
|
I have setup 10 different code variations using layer makers to trigger the expressions. Some of these are very similar but they give a better overall view of the possibilities available.
(1) Ramp Up Reset [between Markers]
The code below starts increasing from zero at the first marker and continues to increase to a value of 1 at the next marker. The distance between the markers determines the speed to the increase and the value never goes higher than 1. Repeat and Reset at next marker.
(There MUST be a layer marker at past the end of the layer for this expression to work, see AE file)
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
if (marker.key(m).time <= time){
(1/(marker.key(m+1).time-marker.key(m).time))*(time-marker.key(m+1).time)+1
}else if (m != 1){
(1/(marker.key(m).time-marker.key(m-1).time))*(time-marker.key(m).time)+1
}else{
0
}
}else{
0
}
The red dots represent layer markers.
=======================================================================================
(2) Ramp Down Reset [between Markers]
The code below starts decreasing from 1 at the first marker and continues to decrease to a value of 0 at the next marker. The distance between the markers determines the speed to the decrease and the value never goes higher than 1. Resets and Repeats at next marker.
(There MUST be a layer marker at past the end of the layer for this expression to work, see AE file).
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
if (marker.key(m).time <= time){
(-1/(marker.key(m+1).time-marker.key(m).time))*(time-marker.key(m+1).time)
}else if (m != 1){
(-1/(marker.key(m).time-marker.key(m-1).time))*(time-marker.key(m).time)
}else{
0
}
}else{
0
}
The red dots represent layer markers.
=======================================================================================
(3) Ramp Down Reset [1 sec]
The code below starts decreasing from 1 at the first marker and continues to decrease to a value of 0 in 1 sec. The distance between the markers is not important and the value never goes higher than 1. Resets and Repeats at next marker.
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
x=m%2;
if (time-marker.key(m).time<1&&time>=marker.key(m).time){
1-(time-marker.key(m).time)
}else if (marker.key(m).index==1){
0
}else if(time-marker.key(m-1).time<1&&time>=marker.key(m-1).time){
1-(time-marker.key(m-1).time)
}else{
0
}
}else{
0
}
}

The red dots represent layer markers.
=======================================================================================
(4) Ramp Up Reset
The code below starts increasing from 0 at the first marker and continues to increase till the next marker. The distance between the markers determines the value. The final value is equal to the time distance between the markers. Resets and Repeats at next marker. (This is the expression that I found from Dan Ebberts. Thanks again)
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
if (marker.key(m).time <= time){
time-marker.key(m).time
}else if (m != 1){
time -marker.key(m - 1).time
}else{
0
}
}else{
0
}
The red dots represent layer markers.
=======================================================================================
(5) Ramp Up Reset [On/Off]
The code below starts increasing from 0 at the first marker and continues to increase till the next marker. The distance between the markers determines the value. The final value is equal to the time distance between the markers.
Turns off at every EVEN marker then Resets and Repeats at next ODD marker.
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
x=m%2;
if ( marker.key(m).time <= time && x==1){
time-marker.key(m).time
}else if (marker.key(m).time>time && x==0){
time -marker.key(m - 1).time
}else{
0
}
}else{
0
}
The red dots represent layer markers.
=======================================================================================
(6) Ramp Up/Down Reset
The code below starts increasing from 0 at the first marker and continues to increase till halfway to the next marker. Then the value decreases to 0 at the next marker. The distance between the markers determines the maximum value. Resets and Repeats at next marker.
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
if (marker.key(m).time <= time){
time-marker.key(m).time
}else if (m != 1){
marker.key(m).time-time
}else{
0
}
}else{
0
}
The red dots represent layer markers.
=======================================================================================
(7) Step Up
The code below starts with a value of 1 at the first marker and continues to increase by 1 at each additional marker. The total number of markers determines the maximum value.
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
if (marker.key(m).time <= time){
marker.key(m).index
}else if (m != 1){
marker.key(m - 1).index
}else{
0
}
}else{
0
}
The red dots represent layer markers.
=======================================================================================
(8) Step Up [On/Off]
The code below starts with a value of 1 at the first marker. It turns off at every EVEN marker and increases by 1 at every ODD marker. The total number of markers determines the maximum value.
The markers below indicate when the picture to the right switches.
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
x=m%2;
if ( marker.key(m).time <= time && x==1){
if( marker.key(m).index ==1){
marker.key(m).index
}else{
marker.key((0.5*m)+.5).index
}
}else if (marker.key(m).time>time && x==0){
if( marker.key(m).index==2){
marker.key(m-1).index
}else{
marker.key(m/2).index
}
}else{
0
}
}else{
0
}
The red dots represent layer markers.
=======================================================================================
(9) Flat [+/- switch]
The code below starts with a value of +1 at the first marker. It turns to -1 at every EVEN marker and +1 at every ODD marker. Just basically a flip/flop expression. Values between +1/-1.
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
x=m%2;
if ( marker.key(m).time <= time && x==1){
1
}else if (marker.key(m).time>time && x==0){
1
}else if (marker.key(1).time>time && x==1){
0
}else if (marker.key(m).time>time && x==1){
-1
}else{
-1
}
}else{
0
}
The red dots represent layer markers.
======================================================================================
(10) Flat
The code below starts with a value of 1 at the first marker. It turns off at every EVEN marker and back to 1 at every ODD marker. Values between +1/0
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
x=m%2;
if ( marker.key(m).time <= time && x==1){
1
}else if (marker.key(m).time>time && x==0){
1
}else{
0
}
}else{
0
}
The red dots represent layer markers.
Now that the expression sets have been explained individually, combining them together can give many more complex forms possibly to cumbersome to type out in an individual expression.
I expression set (1) is multiplied by itself and then by 100, the final graph looks like this. This gives a second degree polynomial function that starts at zero and ends at 100. Apply this to a layers opacity. Now instead of the linear increase from zero to 1 (the standard code for set 1) the combination returns a much complex range of values based on the layer markers.
The red dots represent layer markers.
I hope that this has been helpful to someone out there. I really enjoyed setting it up and learning as I went. The movie I made is just a quick example of how these expressions can be used. I used no key framing in the animation of these effects. I did manually position the layers, but all movement, opacity changes, color changes and pattern shifts were all controlled by the layer markers for each effect.
The included excel file has the above 10 sets of expressions listed in tabular form. You can pick and choose which sets to add, subtract, multiply and divide. The chart in the file shows the two initial sets and the one produced after the combination. It is useful for seeing how interactions occur. Thanks for reading.
Feel free to post your question on the Adobe After Effects Forum at CreativeCOW.net.
If you found this page from a direct link, please visit our forums or read other articles at CreativeCOW.net
|