Spice up your workflow with these expressions for AfterEffects, GPT4 powered.
ChatGPT, a powerful AI language model by OpenAI, offers an innovative approach to streamlining the scripting process in Adobe After Effects. By leveraging the capabilities of ChatGPT, users can automate repetitive tasks, generate complex expressions, and even create custom effect controls with ease. The natural language processing capabilities of ChatGPT allow users to describe the desired effect or animation in plain English, and the AI model can generate the corresponding script or expression code, saving valuable time and effort. Furthermore, this intelligent assistance can help users explore new creative possibilities by suggesting alternate techniques, effects, or optimizations. As a result, integrating ChatGPT into the After Effects workflow can significantly enhance productivity and foster innovation, empowering users to unlock the true potential of their creative projects.
1. Write an expression for aftereffects on the opacity channel when a marker is set, set a keyframe of opacity 0 at the marktertime -1, 100 at markertime and +10 frames to 0 eased in.
// Name this layer “FLASH” to use the second expression as well
// Variables
markerTime = 0;
OpacityAtMarker = 100;
framesBefore = -1;
framesAfter = 5;
// Find the nearest marker
if (marker.numKeys > 0) {
markerTime = marker.nearestKey(time).time;
}
// Convert time to frames
currentTime = timeToFrames(time, 1 / thisComp.frameDuration, false);
markerFrame = timeToFrames(markerTime, 1 / thisComp.frameDuration, false);
// Determine the keyframes and interpolation
if (currentTime >= markerFrame + framesBefore && currentTime <= markerFrame + framesAfter) {
// Keyframe before marker
t0 = markerFrame + framesBefore; v0 = 0;
// Keyframe at marker
t1 = markerFrame; v1 = opacityAtMarker;
// Keyframe after marker
t2 = markerFrame + framesAfter; v2 = 0;
// Interpolation
if (currentTime < markerFrame) {
linear(currentTime, t0, t1, v0, v1);
} else {
ease(currentTime, t1, t2, v1, v2);
}
} else {
value;
}
2. Write an expression for aftereffects on the timeremapping channel of a precomp that uses the markers from layer “FLASH”, at markertime play the precomp.
// Define variables
framesToPlay = 25;
currentTime = time;
// Find the layer named “FLASH”
flashLayer = thisComp.layer(“FLASH”);
// Find the current and next markers
currentMarker = null;
nextMarker = null;
if (flashLayer.marker.numKeys > 0) {
currentMarker = flashLayer.marker.nearestKey(currentTime);
if (currentMarker.time > currentTime) {
currentMarker = flashLayer.marker.key(Math.max(currentMarker.index – 1, 1));
}
if (currentMarker.index < flashLayer.marker.numKeys) {
nextMarker = flashLayer.marker.key(currentMarker.index + 1);
}
}
// Calculate time remapping
if (currentMarker && (!nextMarker || currentTime < nextMarker.time)) {
if (currentTime – currentMarker.time < framesToPlay * thisComp.frameDuration) {
remappedTime = currentTime – currentMarker.time;
}
else { remappedTime = 0;
}
}
else {
remappedTime = 0;
}
remappedTime;
3. Write an expression for aftereffects that automatically fades in and out based on a layer’s in and out point
// Set the duration of the fade in and fade out
fadeDuration = 0.5;
// Calculate the fade in value based on the in-point
fadeIn = linear(time, inPoint, inPoint + fadeDuration, 0, 100);
// Calculate the fade out value based on the out-point
fadeOut = linear(time, outPoint – fadeDuration, outPoint, 100, 0);
// Combine both fadeIn and fadeOut values for the opacity
opacity = fadeIn + fadeOut – 100;
opacity;
4. Here’s the complete guide to creating a positional audio effect in After Effects, including pan, volume, EQ, and reverb based on the distance from the center of the composition:
- Create a new composition in After Effects.
- Import your audio file into the project panel and add it to the timeline.
- Create a new null object (Layer > New > Null Object) that will represent the position of the sound source.
- With the audio layer selected, apply the “Stereo Mixer” effect (Effect > Audio > Stereo Mixer).
- Apply the “Bass & Treble” effect (Effect > Audio > Bass & Treble).
- Apply the “Reverb” effect (Effect > Audio > Reverb).
Now add the expressions:
- Alt-click on the stopwatch next to the “Left Pan” property of the Stereo Mixer effect and paste the following expression:
var soundSource = thisComp.layer(“Null 1”);
var compCenter = [thisComp.width / 2, thisComp.height / 2];
var positionDifference = soundSource.transform.position – compCenter;
var panValue = linear(positionDifference[0], -thisComp.width / 2, thisComp.width / 2, -100, 100);
panValue;
- Alt-click on the stopwatch next to the “Right Pan” property and paste the same expression as in previous step 7
- Alt-click on the stopwatch next to the “Audio Levels” property of the audio layer and paste the following expression:
var soundSource = thisComp.layer(“Null 1”);
var compCenter = [thisComp.width / 2, thisComp.height / 2];
var positionDifference = soundSource.transform.position – compCenter;
var distance = length(positionDifference);
var maxDistance = Math.sqrt(Math.pow(thisComp.width / 2, 2) + Math.pow(thisComp.height / 2, 2));
var minVolume = -50;
var maxVolume = 0;
var volumeValue = linear(distance, 0, maxDistance, maxVolume, minVolume);
[volumeValue, volumeValue];
10. Alt-click on the stopwatch next to the “Bass” property of the “Bass & Treble” effect and paste the following expression:
var soundSource = thisComp.layer(“Null 1”);
var compCenter = [thisComp.width / 2, thisComp.height / 2];
var positionDifference = soundSource.transform.position – compCenter;
var distance = length(positionDifference);
var maxDistance = Math.sqrt(Math.pow(thisComp.width / 2, 2) + Math.pow(thisComp.height / 2, 2));
var minBass = -100;
var maxBass = 0;
var bassValue = linear(distance, 0, maxDistance, maxBass, minBass);
bassValue;
11. Alt-click on the stopwatch next to the “Dry Out” property of the “Reverb” effect and paste the following expression:
var soundSource = thisComp.layer(“Null 1”);
var compCenter = [thisComp.width / 2, thisComp.height / 2];
var positionDifference = soundSource.transform.position – compCenter;
var distance = length(positionDifference);
var maxDistance = Math.sqrt(Math.pow(thisComp.width / 2, 2) + Math.pow(thisComp.height / 2, 2));
var minValue = 0;
var maxValue = 100;
var dryValue = linear(distance, 0, maxDistance, maxValue, minValue);
dryValue;
Now, as you animate the null object’s position within the composition, the audio layer’s pan, volume,
volume, bass, and reverb properties will be controlled by the expressions, creating an advanced positional audio effect. Remember, this method has its limitations and may not accurately mimic 3D audio or real-world sound behavior. For more precise control and realistic results, consider using dedicated audio editing tools or 3D audio techniques.
As you animate the null object’s position within the composition, the audio layer’s properties will change accordingly. The pan, volume, EQ (bass), and reverb will be adjusted to create the impression of positional audio based on the distance from the center of the composition. This method provides a simple way to simulate positional audio in After Effects but may not be as accurate or immersive as dedicated audio editing tools or 3D audio techniques.