movis.layer#
The layer
module defines base protocols for representing various kind of video layers in Layer
and BasicLayer
.
The remaining classes in this module represent its implementations.
Composition#
A base layer that integrates multiple layers into one video. |
|
A wrapper layer for managing additional info. |
Image, Video, Audio, etc.#
Still image layer to encapsulate various formats of image data and offer time-based keying. |
|
Image sequence layer to encapsulate various formats of images. |
|
Video layer to encapsulate various formats of video data. |
|
Audio layer to encapsulate various formats of audio data. |
|
Audio sequence layer to handle multiple audio files. |
Drawing layers#
Draw a line from |
|
Draw a rectangle with rounded corners. |
|
Draw an ellipse. |
|
Draw a text. |
|
A property for filling a shape. |
|
A property for stroking a shape. |
Texture layers#
A layer that generates a gradient image. |
|
A layer that generates a stripe pattern. |
Layer-to-Layer Composition#
A layer that applies alpha matte to the target layer using the mask layer. |
|
A layer that replaces the alpha channel of the target layer with the luminance of the mask layer. |
Protocol#
- class movis.layer.protocol.Layer(*args, **kwargs)[source]#
The protocol that defimes the minimal interface for a layer.
- __call__(time: float) ndarray | None [source]#
The minimum required method to implement a layer. All layers must implement it.
Specifically, this method returns a
numpy.ndarray
of shape(H, W, 4)
with RGBA order and dtype asnumpy.uint8
, orNone
, given a time. When anumpy.ndarray
is returned, Movis considers this array as an image and uses it as one of the layers for rendering the video. IfNone
is returned, Movis does not render its layer.- Args:
time: A scalar variable representing time.
- Returns:
None
if nothing is to be rendered, otherwisenumpy.ndarray
.
- class movis.layer.protocol.BasicLayer(*args, **kwargs)[source]#
The protocol that defines the basic interface for a layer with some optional properties.
- __call__(time: float) ndarray | None [source]#
The minimum required method to implement a layer. All layers must implement it.
Specifically, this method returns a
numpy.ndarray
of shape(H, W, 4)
with RGBA order and dtype asnumpy.uint8
, orNone
, given a time. When anumpy.ndarray
is returned, Movis considers this array as an image and uses it as one of the layers for rendering the video. IfNone
is returned, Movis does not render its layer.- Args:
time: A scalar variable representing time.
- Returns:
None
if nothing is to be rendered, otherwisenumpy.ndarray
.
- property duration: float#
An optional but desirable property for any layer implementation.
This property should return the duration for which the layer will persist. If not implemented, it is assumed that the layer has an indefinitely large duration.
- Returns:
The duration for which the layer will persist.
- get_key(time: float) Hashable [source]#
An optional but desirable method for any layer implementation.
This method returns a hashable value representing the ‘state’ of the layer at a given time. If the keys are the same, the array returned by this layer must also be identical. It is used for caching compositions, and in the case of videos where static frames persist, Movis will use the cache to accelerate video rendering.
If not implemented, Movis assumes that the layer is independent at each time frame, i.e., it will not use cache-based rendering.
- Returns:
A hashable key that represents the state of the layer at the given time.
- class movis.layer.protocol.AudioLayer(*args, **kwargs)[source]#
- __call__(time: float) ndarray | None [source]#
The minimum required method to implement a layer. All layers must implement it.
Specifically, this method returns a
numpy.ndarray
of shape(H, W, 4)
with RGBA order and dtype asnumpy.uint8
, orNone
, given a time. When anumpy.ndarray
is returned, Movis considers this array as an image and uses it as one of the layers for rendering the video. IfNone
is returned, Movis does not render its layer.- Args:
time: A scalar variable representing time.
- Returns:
None
if nothing is to be rendered, otherwisenumpy.ndarray
.
- get_audio(start_time: float, end_time: float) ndarray | None [source]#
An optional method for implementing an audio layer.
This method returns an audio clip of the layer between the given start and end times. The returned audio clip should be a two-dimensional
numpy.ndarray
with a shape of(2,T)
, whereT
is the number of samples in the audio clip and2
is the number of channels. The sample rate of the audio clip should beAUDIO_SAMPLING_RATE
(= 44100).If not implemented, Movis assumes that the layer does not have any audio.
- Args:
start_time: The start time of the audio clip. end_time: The end time of the audio clip.
- Returns:
A two-dimensional
numpy.ndarray
with a shape of(2,T)
andsample_rate
is an integer representing the sample rate of the audio clip.