Skip to content

🎥 Make videos programmatically with React

make GIFs work with staticFile()

Jonny Burger65188e83a74b
diff --git a/packages/example/public/giphy.gif b/packages/example/public/giphy.gif
new file mode 100644
index 0000000000..9faaf009da
Binary files /dev/null and b/packages/example/public/giphy.gif differ
diff --git a/packages/example/src/GifTest/index.tsx b/packages/example/src/GifTest/index.tsx
index 5d6e14e13e..4b378cc8eb 100644
--- a/packages/example/src/GifTest/index.tsx
+++ b/packages/example/src/GifTest/index.tsx
@@ -1,18 +1,14 @@
-import {Sequence, useVideoConfig} from 'remotion';
import {Gif} from '@remotion/gif';
+import {Sequence, staticFile, useVideoConfig} from 'remotion';
const GifTest: React.FC = () => {
const {width, height} = useVideoConfig();
+ const giphy = staticFile('giphy.gif');
return (
<div style={{flex: 1, backgroundColor: 'black'}}>
<Sequence from={0} durationInFrames={50}>
- <Gif
- src="https://media.giphy.com/media/S9RJG5q2YnWd2nYLZ3/giphy.gif"
- width={width}
- height={height}
- fit="fill"
- />
+ <Gif src={giphy} width={width} height={height} fit="fill" />
</Sequence>
<Sequence from={50} durationInFrames={50}>
diff --git a/packages/gif/src/GifForDevelopment.tsx b/packages/gif/src/GifForDevelopment.tsx
index c66576ab9d..88cfdc64db 100644
--- a/packages/gif/src/GifForDevelopment.tsx
+++ b/packages/gif/src/GifForDevelopment.tsx
@@ -10,8 +10,9 @@ export const GifForDevelopment = forwardRef<
HTMLCanvasElement,
RemotionGifProps
>(({src, width, height, onError, onLoad, fit = 'fill', ...props}, ref) => {
+ const resolvedSrc = new URL(src, window.location.origin).href;
const [state, update] = useState<GifState>(() => {
- const parsedGif = cache.get(src);
+ const parsedGif = cache.get(resolvedSrc);
if (parsedGif === undefined) {
return {
@@ -26,7 +27,7 @@ export const GifForDevelopment = forwardRef<
});
// skip loading if frames exist
- useWorkerParser(Boolean(state.frames.length) || src, (info) => {
+ useWorkerParser(Boolean(state.frames.length) || resolvedSrc, (info) => {
if ('error' in info) {
if (onError) {
onError(info.error);
@@ -40,7 +41,7 @@ export const GifForDevelopment = forwardRef<
} else {
onLoad?.(info);
- cache.set(src, info);
+ cache.set(resolvedSrc, info);
update(info);
}
});
diff --git a/packages/gif/src/GifForRendering.tsx b/packages/gif/src/GifForRendering.tsx
index 82b82324dd..f8320c404f 100644
--- a/packages/gif/src/GifForRendering.tsx
+++ b/packages/gif/src/GifForRendering.tsx
@@ -6,6 +6,7 @@ import {useCurrentGifIndex} from './useCurrentGifIndex';
export const GifForRendering = forwardRef<HTMLCanvasElement, RemotionGifProps>(
({src, width, height, onLoad, onError, fit = 'fill', ...props}, ref) => {
+ const resolvedSrc = new URL(src, window.location.origin).href;
const [state, update] = useState<GifState>({
delays: [],
frames: [],
@@ -14,12 +15,12 @@ export const GifForRendering = forwardRef<HTMLCanvasElement, RemotionGifProps>(
});
const [id] = useState(() =>
- delayRender(`Rendering <Gif/> with src="${src}"`)
+ delayRender(`Rendering <Gif/> with src="${resolvedSrc}"`)
);
const index = useCurrentGifIndex(state.delays);
- useParser(src, (info) => {
+ useParser(resolvedSrc, (info) => {
if ('error' in info) {
if (onError) {
onError(info.error);