π₯ Make videos programmatically with React
note new API availability
Jonny Burger33d5e846c99d
diff --git a/packages/docs/components/TableOfContents/studio.tsx b/packages/docs/components/TableOfContents/studio.tsxnew file mode 100644index 0000000000..e1b63c0a86--- /dev/null+++ b/packages/docs/components/TableOfContents/studio.tsx@@ -0,0 +1,22 @@+import React from "react";+import { Grid } from "./Grid";+import { TOCItem } from "./TOCItem";++export const TableOfContents: React.FC = () => {+ return (+ <div>+ <Grid>+ <TOCItem link="/docs/studio/get-static-files">+ <strong>{"getStaticFiles()"}</strong>+ <div>+ Get a list of files in the <code>public</code> folder+ </div>+ </TOCItem>+ <TOCItem link="/docs/studio/watch-static-file">+ <strong>{"watchStaticFile()"}</strong>+ <div>Listen to changes of a static file</div>+ </TOCItem>+ </Grid>+ </div>+ );+};diff --git a/packages/docs/docs/get-static-files.md b/packages/docs/docs/get-static-files.mdindex 76a2752fdf..d26e85c848 100644--- a/packages/docs/docs/get-static-files.md+++ b/packages/docs/docs/get-static-files.md@@ -7,7 +7,12 @@ crumb: "API"_Available from v3.3.26._-Gets an array containing all files in the `public/` folder. You can reference them by using [`staticFile()`](/docs/staticfile).+:::note+This API is being moved to the `@remotion/studio` package. Prefer importing the API from [`@remotion/studio`](/docs/studio/get-static-files) instead of `remotion`.+:::++Gets an array containing all files in the `public/` folder.+You can reference them by using [`staticFile()`](/docs/staticfile).:::warningThis feature _only_ works in Remotion Studio and during rendering, otherwise it returns an empty array.diff --git a/packages/docs/docs/studio/api.mdx b/packages/docs/docs/studio/api.mdxnew file mode 100644index 0000000000..545ea142a9--- /dev/null+++ b/packages/docs/docs/studio/api.mdx@@ -0,0 +1,16 @@+---+sidebar_label: "@remotion/studio"+title: "@remotion/studio"+---++import { TableOfContents } from "../../components/TableOfContents/studio";++You can install this package from NPM:++<Installation pkg="@remotion/gif" />++## APIs++The following APIs are available:++<TableOfContents />diff --git a/packages/docs/docs/studio/get-static-files.mdx b/packages/docs/docs/studio/get-static-files.mdxnew file mode 100644index 0000000000..e919b0e767--- /dev/null+++ b/packages/docs/docs/studio/get-static-files.mdx@@ -0,0 +1,85 @@+---+title: getStaticFiles()+crumb: "@remotion/studio"+---++# getStaticFiles()<AvailableFrom v="4.0.144"/>++Gets an array containing all files in the `public/` folder. You can reference them by using [`staticFile()`](/docs/staticfile).++:::note+This API is being moved from the <code>remotion</code> package.+Prefer this API over the old one.+:::++:::note+In environments outside the Remotion Studio, this API returns an empty array.+:::++:::note+On Linux, watching for changes in subdirectories is only supported from Node.js v19.1.0. If you use a version earlier than that, you need to refresh the Remotion Studio browser tab manually.+:::++```tsx twoslash title="example.ts"+import { getStaticFiles, StaticFile } from "@remotion/studio";+import { Video } from "remotion";++const files = getStaticFiles();+/*+[+ {+ "name": "video.mp4",+ "src": "/static-7n5spa/video.mp4",+ "sizeInBytes": 432944,+ "lastModified": 1670170466865+ },+ {+ "name": "assets/data.json",+ "src": "/static-7n5spa/assets/data.json",+ "sizeInBytes": 1311,+ "lastModified": 1670170486089+ },+]+*/++// β Don't pass the `name` directly to the `src` of a media element+const videoName = files[0].name;++// β Wrap it in staticFile() instead or use `src`+const videoSrc = files[0].src;++// Find a file by it's name and import it+const data = files.find((f) => {+ return f.name === "video.mp4";+}) as StaticFile; // Use `as StaticFile` to assert the file exists++// Use the `src` property to get a src to pass to a media element+<Video src={data.src} />;+```++## API++Takes no arguments and returns an array of object, each of which have four entries:++- `name`: The path relative to the public folder.+ :::note+ Contains forward slashes `/` even on Windows.+ :::note++- `src`: The path with a prefix. The prefix changes whenever the Studio server restarts.+- `sizeInBytes`: The file size. If it is a symbolic link, the file size of the original is reported.+- `lastModified`: Last modified date in Unix timestamp in milliseconds.++## Maximum files++For performance, only the first 10000 items are fetched and displayed.++**Changelog**++Before v4.0.64, only the first 1000 items were displayed.++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/studio/src/api/get-static-files.ts)+- [`staticFile()`](/docs/staticfile)+- [`watchStaticFile()`](/docs/studio/watch-static-file)diff --git a/packages/docs/docs/studio/watch-static-file.mdx b/packages/docs/docs/studio/watch-static-file.mdxnew file mode 100644index 0000000000..00baa3f51c--- /dev/null+++ b/packages/docs/docs/studio/watch-static-file.mdx@@ -0,0 +1,57 @@+---+image: /generated/articles-docs-watch-static-file.png+title: watchStaticFile()+crumb: "API"+---++# watchStaticFile()<AvailableFrom v="4.0.144"/>++Watches for changes in a specific [static file](/docs/staticfile) and invokes a callback function when the file changes, enabling dynamic updates in your Remotion projects.++:::note+This API is being moved from the <code>remotion</code> package.+Prefer this API over the old one.+:::++:::note+This feature is only available within the Remotion Studio environment. In the Player, events will never fire.+:::++## Example++```tsx twoslash title="example.tsx"+import { StaticFile, watchStaticFile } from "@remotion/studio";++// Watch for changes in a specific static file+const { cancel } = watchStaticFile(+ "your-static-file.jpg",+ (newData: StaticFile | null) => {+ if (newData) {+ console.log(`File ${newData.name} has been added or modified.`);+ } else {+ console.log("File has been deleted.");+ }+ },+);++// To stop watching for changes, call the cancel function+cancel();+```++## Arguments++Takes two arguments and returns a function that can be used to `cancel` the event listener.++### `filename`++A name of the file in `/public` folder to watch for changes.++### `callback`++A callback function that will be called when the file is modified. As an argument, a [`StaticFile`](/docs/getstaticfiles#api) or `null` is passed.++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/studio/src/api/watch-static-file.ts)+- [`staticFile()`](/docs/staticfile)+- [`getStaticFiles()`](/docs/studio/get-static-files)diff --git a/packages/docs/docs/watch-static-file.md b/packages/docs/docs/watch-static-file.mdindex b3b054849c..dcb8c819d8 100644--- a/packages/docs/docs/watch-static-file.md+++ b/packages/docs/docs/watch-static-file.md@@ -7,6 +7,10 @@ crumb: "API"# watchStaticFile()<AvailableFrom v="4.0.61"/>+:::note+This API is being moved to the `@remotion/studio` package. Prefer importing the API from [`@remotion/studio`](/docs/studio/watch-static-file) instead of `remotion`.+:::+Watches for changes in a specific [static file](/docs/staticfile) and invokes a callback function when the file changes, enabling dynamic updates in your Remotion projects.:::warningdiff --git a/packages/docs/package.json b/packages/docs/package.jsonindex b595bd9be6..92dd821b2d 100644--- a/packages/docs/package.json+++ b/packages/docs/package.json@@ -51,6 +51,7 @@"@remotion/rive": "workspace:*","@remotion/shapes": "workspace:*","@remotion/skia": "workspace:*",+ "@remotion/studio": "workspace:*","@remotion/tailwind": "workspace:*","@remotion/three": "workspace:*","@remotion/transitions": "workspace:*",diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 6c260dba26..e76ccaf397 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -422,6 +422,15 @@ module.exports = {},items: ["rive/index", "rive/remotionrivecanvas"],},+ {+ type: "category",+ label: "@remotion/studio",+ link: {+ type: "doc",+ id: "studio/api",+ },+ items: ["studio/get-static-files", "studio/watch-static-file"],+ },{type: "category",label: "@remotion/transitions",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 3f8175fc15..ec4c097446 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -677,6 +677,9 @@ importers:'@remotion/skia':specifier: workspace:*version: link:../skia+ '@remotion/studio':+ specifier: workspace:*+ version: link:../studio'@remotion/tailwind':specifier: workspace:*version: link:../tailwind