Timing and trimming
The way timing works is standardized across these components:
Interactiveelements, such as<Interactive.Div>, and<AbsoluteFill>.<Img>,<CanvasImage>,<AnimatedImage>,<Solid>and<HtmlInCanvas>.<HtmlInCanvasMotionBlur>from@remotion/motion-blur.<Gif>,<Lottie>,<ThreeCanvas>and<RemotionRiveCanvas>.@remotion/shapes,@remotion/rough-notation,<MacOSCursor>.<Audio>and<Video>from@remotion/media.- Custom components built with
Interactive.withSchema()that expose these props.
from: Move an item
from moves an item on its parent timeline. By default, its children start at frame 0 when it appears:
MyComposition.tsximport {Interactive ,useCurrentFrame } from 'remotion'; constCounter = () => <div >{useCurrentFrame ()}</div >; export constMyComposition = () => ( <Interactive .Div from ={30}> <Counter /> </Interactive .Div > );
durationInFrames: Limit an item
durationInFrames sets how long an item stays on its parent timeline, starting at from.
MyComposition.tsximport {Interactive ,useCurrentFrame } from 'remotion'; constCounter = () => <div >{useCurrentFrame ()}</div >; export constMyComposition = () => ( <Interactive .Div from ={30}durationInFrames ={45}> <Counter /> </Interactive .Div > );
trimBefore: Trim the beginning
trimBefore skips the beginning of an item's content without moving it from its from position.
MyComposition.tsximport {Interactive ,useCurrentFrame } from 'remotion'; constCounter = () => <div >{useCurrentFrame ()}</div >; export constMyComposition = () => ( <Interactive .Div from ={30}trimBefore ={15}> <Counter /> </Interactive .Div > );
playbackRate: Change speed of an item
playbackRate on <Interactive.Div> changes how quickly its children's frame advances.
MyComposition.tsximport {Interactive ,useCurrentFrame } from 'remotion'; constCounter = () => <div >{useCurrentFrame ()}</div >; export constMyComposition = () => ( <Interactive .Div from ={30}trimBefore ={15}playbackRate ={2} > <Counter /> </Interactive .Div > );
trimAfter: Trim video or audio
<Audio> and <Video> also accept trimAfter to select where playback stops in the video or audio.
At 30 composition FPS, trimBefore={45} and trimAfter={105} select the source from 1.5 to 3.5 seconds.
MyComposition.tsximport {staticFile } from 'remotion'; import {Video } from '@remotion/media'; export constMyComposition = () => ( <Video src ={staticFile ('video.mp4')}from ={30}trimBefore ={45}trimAfter ={105}playbackRate ={2} /> );
loop: Repeat video or audio
loop on <Audio> and <Video> repeats the source range selected by trimBefore and trimAfter.
If trimAfter is omitted, it loops from trimBefore after the end of the source.
MyComposition.tsximport {staticFile } from 'remotion'; import {Video } from '@remotion/media'; export constMyComposition = () => ( <Video src ={staticFile ('video.mp4')}from ={30}trimBefore ={45}trimAfter ={105}playbackRate ={2}loop durationInFrames ={90} /> );
At 30 FPS, this repeats the selected 60 source frames three times over 90 composition frames.
Order of operations
Think of the timing props as applying to the content in this order:
from,trimBeforeandtrimAfterdefines the selected source rangeplaybackRatestretches or compresses the selected rangeloop(on<Audio>and<Video>) loops the stretched rangedurationInFramesis applied last and defines the duration of the item in the timeline.
For an item with children, useCurrentFrame() at parent frame t is:
trimBefore + (t - from) * playbackRate