Projects and compositions¶
A project defines the video size, frame rate and duration. Its root composition
holds the visual layers that appear in the video. Use this guide for setup;
the authoring model explains sources,
placements and snapshot copies. Start a new compositions.py below; it needs
no input files.
The render calls below use overwrite=True; rerunning a script replaces its
named output files.
from vestra import Group, Project
from vestra.sources import Color, Rectangle
project = Project(
size=(1280, 720),
fps=30,
duration=5,
)
project.root.add(Color("#111827"), duration=5, id="background")
# Show a blue panel from second 1 until second 3.
panel = project.root.add(
Rectangle(width=600, height=180, fill="#2563eb"),
start=1,
duration=2,
z=1,
id="panel",
)
start and duration control when a layer appears. z controls which layers
appear on top: higher values draw over lower ones. IDs are optional, but naming
important layers makes diagnostic messages and later edits easier to follow.
Keep related layers in a group¶
Continue the same project. Build a standalone Group, add its children, then
place the completed source.
Moving, scaling or rotating the returned placement also transforms its children:
card = Group(size=(500, 220))
card.add(
Rectangle(width=500, height=220, fill="#f9fafb"),
duration=3,
)
# A coloured stripe appears a little after the card itself.
card.add(
Rectangle(width=360, height=12, fill="#2563eb"),
start=0.25,
duration=2,
position=(0.5, 0.7),
)
card_layer = project.root.add(
card,
start=1,
duration=3,
z=2,
id="card",
)
card_layer.transform.rotation.keyframe(0, -5)
card_layer.transform.rotation.keyframe(3, 5)
Children use time measured from the beginning of their group. The card starts
at second 1 of the project, so its stripe appears at second 1.25. The group's
rotation runs over its own three-second duration and affects both rectangles.
Finish building card before placing it: add(card) copies its current contents.
The groups concept shows local coordinates,
local time and the difference from root.group(). Use
nested compositions for reuse and direct child editing.
Set a duration¶
An explicit project duration fixes the output length. Content extending beyond it is clipped, and shorter content can leave a background or silent tail. Without one, non-video layers need an explicit duration or a duration supplied by their composition; video layers can use their remaining media duration.
An omitted non-video duration inherits the whole containing duration, even when
start is later than zero. It does not mean “until the project ends.” For a layer
starting at 1 in a five-second project, use duration=4 to end at 5.
Timeline and time
explains automatic duration and frame boundaries.
Export the composition¶
Finish compositions.py after the group placement:
This writes compositions.mp4 in the current directory and replaces it on a
rerun. The output lasts five seconds; the grouped card appears from second 1
to second 4.
Continue with sources and layers to add media or text, or rendering and preparation to export the project and understand validation and runtime checks.