Layers
Video layers are individual components on top of a primary video stream or a blank composition. Overall, video layers provide a powerful tool for creating and editing composite video experiences.
Our Composition API allows you to combine different types of layers, such as video clips, audio, and text, and control their output using tools like blending modes, effects, and keyframes. You can stack multiple layers on top of each other and adjust their position and appearance to create a wide range of effects.
Interface
You can add any of these layer types to a composition by calling it's associated add<LayerType>
method. Each one of these methods adhere to the same interface:
(file, options?, layerConfig?)
- Name
file
- Type
- URL or CompositionFile
- required
- Description
If the layer type involves a file, this will be the first argument
- Name
options
- Type
- object
- Description
If the layer type has layer-specific options, this will be the next argument
- Name
layerConfig
- Type
- object
- Description
If the layer type allows you to set configuration options, this will be the final argument
Classes
Every add<LayerType>
method returns an instantiated class representing the type of layer you've added. This class has getter and chainable setter methods for all of the attributes that you can provide in the options
and layerConfig
arguments. For example, a call to composition.addAudio
will return an instance of the Audio
class.
Configuration
Most layers take an optional layerConfig
argument that allows you to configure aspects of the layer that are common to other layers. See the layer configuration page for more information.
Example using an audio layer:
Configuration
const audio = await composition.addAudio(
"path/to/audio.mp3",
{ volume: 0.5 },
{
timeline: { start: 3 },
trim: { start: 2, end: 6 },
}
);
Setter methods
const audio = await composition.addAudio("path/to/audio.mp3");
audio.setVolume(0.5).setStart(3).setTrim(2, 6);
Accessing attributes
audio.volume; // 0.5
audio.start; // 3
audio.trim; // { start: 2, end: 6 }
Types
Explore the different types of layers you can add to a composition: