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#

movis.layer.composition.Composition

A base layer that integrates multiple layers into one video.

movis.layer.composition.LayerItem

A wrapper layer for managing additional info.

Image, Video, Audio, etc.#

movis.layer.media.Image

Still image layer to encapsulate various formats of image data and offer time-based keying.

movis.layer.media.ImageSequence

Image sequence layer to encapsulate various formats of images.

movis.layer.media.Video

Video layer to encapsulate various formats of video data.

movis.layer.media.Audio

Audio layer to encapsulate various formats of audio data.

movis.layer.media.AudioSequence

Audio sequence layer to handle multiple audio files.

Drawing layers#

movis.layer.drawing.Line

Draw a line from start to end.

movis.layer.drawing.Rectangle

Draw a rectangle with rounded corners.

movis.layer.drawing.Ellipse

Draw an ellipse.

movis.layer.drawing.Text

Draw a text.

movis.layer.drawing.FillProperty

A property for filling a shape.

movis.layer.drawing.StrokeProperty

A property for stroking a shape.

Texture layers#

movis.layer.texture.Gradient

A layer that generates a gradient image.

movis.layer.texture.Stripe

A layer that generates a stripe pattern.

Layer-to-Layer Composition#

movis.layer.layer_ops.AlphaMatte

A layer that applies alpha matte to the target layer using the mask layer.

movis.layer.layer_ops.LuminanceMatte

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 as numpy.uint8, or None, given a time. When a numpy.ndarray is returned, Movis considers this array as an image and uses it as one of the layers for rendering the video. If None is returned, Movis does not render its layer.

Args:

time: A scalar variable representing time.

Returns:

None if nothing is to be rendered, otherwise numpy.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 as numpy.uint8, or None, given a time. When a numpy.ndarray is returned, Movis considers this array as an image and uses it as one of the layers for rendering the video. If None is returned, Movis does not render its layer.

Args:

time: A scalar variable representing time.

Returns:

None if nothing is to be rendered, otherwise numpy.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 as numpy.uint8, or None, given a time. When a numpy.ndarray is returned, Movis considers this array as an image and uses it as one of the layers for rendering the video. If None is returned, Movis does not render its layer.

Args:

time: A scalar variable representing time.

Returns:

None if nothing is to be rendered, otherwise numpy.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), where T is the number of samples in the audio clip and 2 is the number of channels. The sample rate of the audio clip should be AUDIO_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) and sample_rate is an integer representing the sample rate of the audio clip.