Custom timings
This page describes how to create your own custom timings for <TransitionSeries>
.
Concept
A timing is a configuration which includes:
Implementation
To implement a custom timing function, create a function which returns an object TransitionTiming
.
custom-timing.tstsx
import type {TransitionTiming } from "@remotion/transitions";constcustomTiming = ():TransitionTiming => {return {getDurationInFrames : ({fps }) =>fps , // 1 secondgetProgress : ({frame ,fps }) =>Math .min (1,frame /fps ),};};
custom-timing.tstsx
import type {TransitionTiming } from "@remotion/transitions";constcustomTiming = ():TransitionTiming => {return {getDurationInFrames : ({fps }) =>fps , // 1 secondgetProgress : ({frame ,fps }) =>Math .min (1,frame /fps ),};};
In this example, the timing function will last for 1 second and will be linear.
Advanced example
In the following example:
spring-timing-with-pause.tstsx
import type {TransitionTiming } from "@remotion/transitions";import {measureSpring ,spring ,SpringConfig } from "remotion";constspringTimingWithPause = ({pauseDuration ,}: {pauseDuration : number;}):TransitionTiming => {constfirstHalf :Partial <SpringConfig > = {};constsecondPush :Partial <SpringConfig > = {damping : 200,};return {getDurationInFrames : ({fps }) => {return (measureSpring ({fps ,config :firstHalf }) +measureSpring ({fps ,config :secondPush }) +pauseDuration );},getProgress ({fps ,frame }) {constfirst =spring ({fps ,frame ,config :firstHalf });constsecond =spring ({fps ,frame ,config :secondPush ,delay :pauseDuration +measureSpring ({fps ,config :firstHalf }),});returnfirst / 2 +second / 2;},};};
spring-timing-with-pause.tstsx
import type {TransitionTiming } from "@remotion/transitions";import {measureSpring ,spring ,SpringConfig } from "remotion";constspringTimingWithPause = ({pauseDuration ,}: {pauseDuration : number;}):TransitionTiming => {constfirstHalf :Partial <SpringConfig > = {};constsecondPush :Partial <SpringConfig > = {damping : 200,};return {getDurationInFrames : ({fps }) => {return (measureSpring ({fps ,config :firstHalf }) +measureSpring ({fps ,config :secondPush }) +pauseDuration );},getProgress ({fps ,frame }) {constfirst =spring ({fps ,frame ,config :firstHalf });constsecond =spring ({fps ,frame ,config :secondPush ,delay :pauseDuration +measureSpring ({fps ,config :firstHalf }),});returnfirst / 2 +second / 2;},};};
The duration needs to be calculated deterministically by adding the duration of the two springs and the pause duration, so that the previous and next scenes are timed correctly.
A spring()
animation by default goes from 0 to 1, which is why they can be added together.
Using a custom timing
You may use a custom timing like any other timing by calling it and passing it to the timing
prop of <TransitionSeries.Transition>
.
using-custom-timing.tsxtsx
import {TransitionSeries } from "@remotion/transitions";import {slide } from "@remotion/transitions/slide";import {useVideoConfig } from "remotion";export constCustomTransition :React .FC = () => {const {width ,height } =useVideoConfig ();return (<TransitionSeries ><TransitionSeries .Sequence durationInFrames ={80}><Letter color ="orange">A</Letter ></TransitionSeries .Sequence ><TransitionSeries .Transition presentation ={slide ({direction : "from-left" })}timing ={customTiming ({pauseDuration : 10 })}/><TransitionSeries .Sequence durationInFrames ={200}><Letter color ="pink">B</Letter ></TransitionSeries .Sequence ></TransitionSeries >);};
using-custom-timing.tsxtsx
import {TransitionSeries } from "@remotion/transitions";import {slide } from "@remotion/transitions/slide";import {useVideoConfig } from "remotion";export constCustomTransition :React .FC = () => {const {width ,height } =useVideoConfig ();return (<TransitionSeries ><TransitionSeries .Sequence durationInFrames ={80}><Letter color ="orange">A</Letter ></TransitionSeries .Sequence ><TransitionSeries .Transition presentation ={slide ({direction : "from-left" })}timing ={customTiming ({pauseDuration : 10 })}/><TransitionSeries .Sequence durationInFrames ={200}><Letter color ="pink">B</Letter ></TransitionSeries .Sequence ></TransitionSeries >);};
Getting the duration of a timing
Call .getDurationInFrames({fps})
on any timing function and pass fps
to get the duration in frames.
References
See the source code for already implemented timings here.