Transitions (View/Rescaler)
This guide will show a few basic examples of animated transitions on View
/Rescaler
components.
Configure inputs and output
Start the compositor and configure 2 input streams and a single output stream as described in the "Simple scene" guide in the "Configure inputs and output" section.
Transition that changes the width
of an input stream
- HTTP
- Membrane Framework
Set initial scene for the transition:
POST: /api/output/output_1/update
Content-Type: application/json
{
"video": {
"root": {
"type": "view",
"background_color_rgba": "#4d4d4dff",
"children": [
{
"type": "rescaler",
"id": "rescaler_1",
"width": 480,
"child": { "type": "input_stream", "input_id": "input_1" },
}
]
}
}
}
A few seconds latter update a scene with a different width
:
POST: /api/output/output_1/update
Content-Type: application/json
{
"video": {
"root": {
"type": "view",
"background_color_rgba": "#4d4d4dff",
"children": [
{
"type": "rescaler",
"id": "rescaler_1",
"width": 1280,
"transition": { "duration_ms": 2000 },
"child": { "type": "input_stream", "input_id": "input_1" },
}
]
}
}
}
Set initial scene for the transition and after few seconds update a component
with a different width
:
def handle_setup(ctx, state) do
request = %LiveCompositor.Request.UpdateVideoOutput{
output_id: "output_1",
root: %{
type: :view,
background_color_rgba: "#4d4d4dff",
children: [
%{
type: :rescaler,
id: "rescaler_1",
width: 480,
child: %{ type: :input_stream, input_id: :input_1 },
}
]
}
}
Process.send_after(self(), :start_transition, 2000)
{[notify_child: {:live_compositor, request}], state}
end
def handle_info(:start_transition, _ctx, state)
request = %LiveCompositor.Request.UpdateVideoOutput{
output_id: "output_1",
root: %{
type: :view,
background_color_rgba: "#4d4d4dff",
children: [
%{
type: :rescaler,
id: "rescaler_1",
width: 1280,
transition: %{ duration_ms: 2000 },
child: %{ type: :input_stream, input_id: :input_1 },
}
]
}
}
{[notify_child: {:live_compositor, request}], state}
end
In the first update request, you can see that the rescaler has a width of 480, and in the second one, it is changed
to 1280 and transition.duration_ms: 2000
was added.
The component must have the same "id"
in both the initial state and the update that starts the
transition, otherwise it will switch immediately to the new state without a transition.
Output stream