movis.contrib.presentation.Character#
- class movis.contrib.presentation.Character(start_times: Sequence[float], end_times: Sequence[float], character_name: str, character_dir: str | PathLike, characters: Sequence[str], character_status: Sequence[str], initial_status: str = 'n', blink_per_minute: int = 3, blink_duration: float = 0.2)[source]#
Character layer for showing and animating characters.
Some presentation videos may place characters who speak with different facial expressions depending on the situation. This layer mimics such a situation.
- Args:
- start_times:
A list of start times in seconds at which the character’s status will change. Should have the same length as characters and character_status.
- end_times:
A list of end times in seconds corresponding to each status duration.
- character_name:
The name of the character that this layer will manage.
- character_dir:
The directory where images corresponding to the character’s emotions are stored. For each emotion, there should be an image named <emotion>.png and an optional eye image named <emotion>.eye.png, <emotion>.eye.0.png, <emotion>.eye.1.png, …
- characters:
A list of character names for which the timeline events are defined. Should have the same length as
start_times
andcharacter_status
.- character_status:
A list specifying the emotion or state of the character at the corresponding start time. Should have the same length as start_times and characters.
- initial_status:
The initial emotion or state of the character before any timeline events occur. Defaults to “n” (Normal).
- blink_per_minute (int, optional):
Number of times the character blinks per minute. Defaults to 3.
- blink_duration (float, optional):
Duration of a single blink in seconds. Defaults to 0.2.
- Examples:
>>> from movis.contrib.commentary import Character >>> # Show a character named "alice" from 0.0 to 10.0 seconds. >>> # Alice's emotion does not change and only displays "character/alice/n.png". >>> alice = Character([0.0, 5.0], [5.0, 10.0], "alice", "character/alice", ["alice", "bob"], ["n", "h"]) >>> # Show a character named "bob" from 0.0 to 10.0 seconds. >>> # Initially Bob's emotion is "n" (Normal), but it changes to "h" (Happy) at 5.0 seconds. >>> # In this case, "n" means "character/bob/n.png" and "h" means "character/bob/h.png". >>> bob = Character([0.0, 5.0], [5.0, 10.0], "bob", "character/bob", ["alice", "bob"], ["n", "h"]) >>> # If "character/bob" contains "n.eye.png" and "n.eye.0.png, "n.eye.1.png", ..., "n.eye.N.png", >>> # in the "n" state, Bob's eyes blink an average of three times per minute. and duration is 0.2 seconds.
Methods
- get_state(time: float) int #
Returns the index of the state at the given time, or
-1
if no state exists.
Attributes
duration
Returns the duration of the timeline.