Skip to content

🎥 Make videos programmatically with React

1.6 KB
Raw Blame
import {Gif} from '@remotion/gif';
import {useRef} from 'react';
import {staticFile, useVideoConfig} from 'remotion';

const GifTest: React.FC = () => {
	const {width, height} = useVideoConfig();
	const giphy = staticFile('giphy.gif');
	const ref1 = useRef<HTMLCanvasElement>(null);
	const ref2 = useRef<HTMLCanvasElement>(null);
	const ref3 = useRef<HTMLCanvasElement>(null);
	const ref4 = useRef<HTMLCanvasElement>(null);

	return (
		<div style={{flex: 1, backgroundColor: 'black'}}>
			<Gif
				ref={ref1}
				playbackRate={4}
				src={giphy}
				width={width}
				height={height}
				fit="fill"
				delayRenderTimeoutInMilliseconds={60000}
				durationInFrames={50}
				trimBefore={28}
				premountFor={30}
				freeze={null}
			/>
			<Gif
				ref={ref2}
				src="https://media.giphy.com/media/xT0GqH01ZyKwd3aT3G/giphy.gif"
				width={width}
				height={height}
				fit="cover"
				from={50}
				durationInFrames={50}
			/>
			<Gif
				ref={ref3}
				src="https://media.giphy.com/media/3o72F7YT6s0EMFI0Za/giphy.gif"
				width={width}
				height={height}
				fit="contain"
				from={100}
				durationInFrames={50}
			/>
			<Gif
				ref={ref4}
				src={staticFile('disposal-type-3.gif')}
				width={width}
				height={height}
				fit="fill"
				from={150}
				durationInFrames={50}
				style={{
					backgroundColor: 'white',
				}}
			/>
			<Gif
				ref={ref4}
				src={staticFile('non-animated-interlaced.gif')}
				width={width}
				height={height}
				fit="fill"
				from={200}
				durationInFrames={50}
				style={{
					backgroundColor: 'white',
				}}
				premountFor={15}
			/>
		</div>
	);
};

export default GifTest;