Skip to content

🎥 Make videos programmatically with React

4.4 KB
Raw Blame
import React from 'react';
import {
	Easing,
	Interactive,
	interpolate,
	useCurrentFrame,
	useVideoConfig,
	type InteractiveTransformProps,
} from 'remotion';

const location = 'Berlin, Germany';

const LocationLowerThirdInner: React.FC<InteractiveTransformProps> = ({
	style,
}) => {
	const frame = useCurrentFrame();
	const {durationInFrames} = useVideoConfig();
	return (
		<Interactive.Div
			name="Container"
			showInTimeline={false}
			style={{
				position: 'relative',
				width: 680,
				height: 138,
				boxSizing: 'border-box',
				fontFamily: 'Arial, Helvetica, sans-serif',
				...style,
			}}
		>
			<Interactive.Svg
				name="Location pin"
				viewBox="0 0 64 80"
				style={{
					position: 'absolute',
					left: 56,
					top: 4,
					width: 104,
					height: 130,
					overflow: 'visible',
					filter: 'drop-shadow(0 6px 8px rgba(24, 24, 27, 0.14))',
					opacity: interpolate(
						frame,
						[0, 9, durationInFrames - 12, durationInFrames - 1],
						[0, 1, 1, 0],
						{
							extrapolateLeft: 'clamp',
							extrapolateRight: 'clamp',
						},
					),
					translate: interpolate(
						frame,
						[0, 16, durationInFrames - 14, durationInFrames - 1],
						['0px -10px', '0px 0px', '0px 0px', '0px -8px'],
						{
							easing: Easing.out(Easing.cubic),
							extrapolateLeft: 'clamp',
							extrapolateRight: 'clamp',
						},
					),
					scale: interpolate(
						frame,
						[0, 16, durationInFrames - 14, durationInFrames - 1],
						[0.88, 1, 1, 0.92],
						{
							easing: Easing.out(Easing.cubic),
							extrapolateLeft: 'clamp',
							extrapolateRight: 'clamp',
						},
					),
					transformOrigin: '52px 126px',
				}}
			>
				<path
					d="M32 3C15.4 3 4 15.4 4 31C4 50.8 22.1 69.6 29.3 76.2C30.8 77.6 33.2 77.6 34.7 76.2C41.9 69.6 60 50.8 60 31C60 15.4 48.6 3 32 3Z"
					pathLength="1"
					fill="#2563eb"
					fillOpacity={interpolate(
						frame,
						[5, 18, durationInFrames - 15, durationInFrames - 6],
						[0, 1, 1, 0],
						{
							extrapolateLeft: 'clamp',
							extrapolateRight: 'clamp',
						},
					)}
					stroke="#2563eb"
					strokeDasharray="1"
					strokeDashoffset={interpolate(
						frame,
						[0, 16, durationInFrames - 15, durationInFrames - 4],
						[1, 0, 0, 1],
						{
							easing: Easing.out(Easing.cubic),
							extrapolateLeft: 'clamp',
							extrapolateRight: 'clamp',
						},
					)}
					strokeLinecap="round"
					strokeLinejoin="round"
					strokeWidth="2.5"
				/>
				<circle
					cx="32"
					cy="30"
					r={interpolate(
						frame,
						[10, 21, durationInFrames - 18, durationInFrames - 8],
						[0, 9, 9, 0],
						{
							easing: Easing.out(Easing.cubic),
							extrapolateLeft: 'clamp',
							extrapolateRight: 'clamp',
						},
					)}
					fill="#eff6ff"
				/>
			</Interactive.Svg>

			<div
				style={{
					position: 'absolute',
					left: 184,
					top: 3,
					width: 440,
					height: 132,
					display: 'flex',
					flexDirection: 'column',
					justifyContent: 'center',
				}}
			>
				<div
					style={{
						height: 82,
						display: 'flex',
						alignItems: 'center',
					}}
				>
					<Interactive.Div
						cropRight={interpolate(
							frame,
							[14, 38, durationInFrames - 32, durationInFrames - 12],
							[1, 0, 0, 1],
							{
								extrapolateLeft: 'clamp',
								extrapolateRight: 'clamp',

								easing: [
									Easing.spring({
										damping: 200,
										mass: 1,
										stiffness: 100,
										allowTail: true,
										durationRestThreshold: 0.02,
										overshootClamping: false,
									}),
									Easing.linear,
									Easing.spring({
										damping: 200,
										mass: 1,
										stiffness: 100,
										allowTail: true,
										durationRestThreshold: 0.02,
										overshootClamping: false,
									}),
								],
							},
						)}
						name="Location"
						dir="auto"
						style={{
							minWidth: 0,
							color: '#18181b',
							fontSize: 54,
							fontWeight: 700,
							letterSpacing: -1,
							textOverflow: 'ellipsis',
							whiteSpace: 'nowrap',
							opacity: interpolate(
								frame,
								[14, 22, durationInFrames - 22, durationInFrames - 10],
								[0, 1, 1, 0],
								{
									extrapolateLeft: 'clamp',
									extrapolateRight: 'clamp',
								},
							),
						}}
					>
						{location}
					</Interactive.Div>
				</div>
			</div>
		</Interactive.Div>
	);
};

export const LocationLowerThird = Interactive.create({
	Component: LocationLowerThirdInner,
	componentName: '<LocationLowerThird>',
});