🎥 Make videos programmatically with React
preloadGif() API
Jonny Burgerdda8c4a7b595
diff --git a/packages/docs/components/TableOfContents/gif.tsx b/packages/docs/components/TableOfContents/gif.tsxindex 4f437003c1..0f2b447d74 100644--- a/packages/docs/components/TableOfContents/gif.tsx+++ b/packages/docs/components/TableOfContents/gif.tsx@@ -14,6 +14,10 @@ export const TableOfContents: React.FC = () => {<strong>getGifDurationInSeconds()</strong><div>Get the runtime of a GIF</div></TOCItem>+ <TOCItem link="/docs/gif/preload-gif">+ <strong>preloadGif()</strong>+ <div>Prepare a GIF for displaying in the Player</div>+ </TOCItem></Grid></div>);diff --git a/packages/docs/docs/gif/preload-gif.md b/packages/docs/docs/gif/preload-gif.mdnew file mode 100644index 0000000000..85b2e8d554--- /dev/null+++ b/packages/docs/docs/gif/preload-gif.md@@ -0,0 +1,31 @@+---+image: /generated/articles-docs-gif-preload-gif.png+title: preloadGif()+crumb: "@remotion/gif"+---++_available from v3.3.38_++Call `preloadGif(src)` with the URL of the GIF that you would like to load and the GIF will be prepared for display in the [`<Player>`](/docs/player).++The function returns an object with two entries: `waitUntilDone()` that returns a Promise which can be awaited and `free()` which will cancel preloading or free up the memory if the GIF is not being used anymore.++```ts twoslash+import { preloadGif } from "@remotion/gif";++const { waitUntilDone, free } = preloadGif(+ "https://media.giphy.com/media/xT0GqH01ZyKwd3aT3G/giphy.gif"+);++waitUntilDone().then(() => {+ console.log("The GIF is now ready to play!");++ // Later, free the memory of the GIF+ free();+});+```++## See also++- [`<Gif>`](/docs/gif)+- [Preloading](/docs/preload)diff --git a/packages/docs/docs/player/preloading.md b/packages/docs/docs/player/preloading.mdindex 66e0520439..355b105523 100644--- a/packages/docs/docs/player/preloading.md+++ b/packages/docs/docs/player/preloading.md@@ -157,6 +157,10 @@ free();</tr></table>+## Preloading GIFs++You can preload and preparse GIFs using [`preloadGif()`](/docs/gif/preload-gif)+## See also- [`@remotion/preload`](/docs/preload)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 57e411467b..bd23c724af 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -131,7 +131,7 @@ module.exports = {type: "doc",id: "gif/index",},- items: ["gif/gif", "gif/get-gif-duration-in-seconds"],+ items: ["gif/gif", "gif/get-gif-duration-in-seconds", "gif/preload-gif"],},{type: "category",diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 78192f62bf..f26dc79dab 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -384,6 +384,13 @@ export const articles = [compId: "articles-docs-gif-index",crumb: null,},+ {+ id: "gif/preload-gif",+ title: "preloadGif()",+ relativePath: "docs/gif/preload-gif.md",+ compId: "articles-docs-gif-preload-gif",+ crumb: "@remotion/gif",+ },{id: "google-fonts/get-available-fonts",title: "getAvailableFonts()",diff --git a/packages/docs/static/generated/articles-docs-gif-preload-gif.png b/packages/docs/static/generated/articles-docs-gif-preload-gif.pngnew file mode 100644index 0000000000..12241d5178Binary files /dev/null and b/packages/docs/static/generated/articles-docs-gif-preload-gif.png differdiff --git a/packages/gif/src/index.ts b/packages/gif/src/index.tsindex c08c92ddb0..b61f7080db 100644--- a/packages/gif/src/index.ts+++ b/packages/gif/src/index.ts@@ -1,3 +1,4 @@export {getGifDurationInSeconds} from './get-gif-duration-in-seconds';export {Gif} from './Gif';+export {preloadGif} from './preload-gif';export {GifFillMode, RemotionGifProps} from './props';diff --git a/packages/gif/src/preload-gif.ts b/packages/gif/src/preload-gif.tsindex 3bc26cf5c7..9210a5ded7 100644--- a/packages/gif/src/preload-gif.ts+++ b/packages/gif/src/preload-gif.ts@@ -5,14 +5,14 @@ import {resolveGifSource} from './resolve-gif-source';export const preloadGif = (src: string): {- waitForDone: () => Promise<void>;+ waitUntilDone: () => Promise<void>;free: () => void;} => {const resolvedSrc = resolveGifSource(src);if (gifCache.has(resolvedSrc)) {return {- waitForDone: () => Promise.resolve(),+ waitUntilDone: () => Promise.resolve(),free: () => gifCache.delete(resolvedSrc),};}@@ -20,7 +20,7 @@ export const preloadGif = (const {prom, cancel} = parseWithWorker(resolvedSrc);return {- waitForDone: () => prom.then(() => undefined),+ waitUntilDone: () => prom.then(() => undefined),free: () => {cancel();gifCache.delete(resolvedSrc);