🎥 Make videos programmatically with React
New articles
Jonny Burgerdc97e958f0e0
diff --git a/packages/docs/docs/importing-assets.md b/packages/docs/docs/importing-assets.mdindex f266a1582a..55a13fa4f5 100644--- a/packages/docs/docs/importing-assets.md+++ b/packages/docs/docs/importing-assets.md@@ -191,8 +191,17 @@ Remotion runs in the browser, so it does not have access to arbitrary files on yIt is also not possible to use the `fs` module from Node.js in the browser.Instead, put assets in the `public/` folder and use [`getStaticFiles()`](/docs/getstaticfiles) to enumerate them.+See [why does Remotion does not support absolute paths](/docs/miscellaneous/absolute-paths).+## Adding assets after bundlingBefore rendering, the code gets bundled using Webpack, and only bundled assets can be accessed afterwards.For this reason, assets that are being added to the public folder after [`bundle()`](/docs/bundle) is called will not be accessible during render.However, if you use the [server-side rendering APIs](/docs/ssr-node), you can add assets to the `public` folder that is inside the bundle after the fact.++## See also++- [staticFile()](/docs/staticfile)+- [getStaticFiles()](/docs/getstaticfiles)+- [watchStaticFile()](/docs/watchstaticfile)+- [Why Remotion does not support absolute paths](/docs/miscellaneous/absolute-paths)diff --git a/packages/docs/docs/miscellaneous/absolute-paths.md b/packages/docs/docs/miscellaneous/absolute-paths.mdnew file mode 100644index 0000000000..badfa5245d--- /dev/null+++ b/packages/docs/docs/miscellaneous/absolute-paths.md@@ -0,0 +1,84 @@+---+image: /generated/articles-docs-miscellaneous-absolute-paths.png+sidebar_label: Absolute paths+title: Files with absolute paths+crumb: "FAQ"+---++Why is it not possible to use absolute paths to require assets?++```tsx title="This does not work"+import { Img } from "remotion";++const MyComp: React.FC = () => {+ return <Img src="C://Users/Joe/Documents/image.png" />;+};+```++## Browsers don't have access to your filesystem++Remotion runs in a browser during preview and in a headless browser during rendering.+By default, browsers don't have access to your filesystem. To read any files, they need to be served via an HTTP server.++## Only the `public` folder is supported by web frameworks++To allow importing assets, frameworks for making web apps such as Next.js, Vite, Remix or Create React App expose the `public` folder.++We follow this convention in Remotion to allow for seamless code reuse across frameworks - assets that show up in the [Remotion Studio](/docs/studio) also show up in the [Remotion Player](/docs/player).++Allowing assets to be imported from any folder would break this convention, and they could not be displayed in the Remotion Player.++<details>+<summary>+The <code>public</code> folder convention+</summary>++Remotion implements a convention where the <code>public</code> folder in your project is exposed via HTTP server and can be accessed on the same domain as your development server.++In Next.js, Remix, and Vite, if you have a file `public/image.png`, you can access it via `"http://localhost:3000/image.png"`, or just `"/image.png"`++In Remotion you need to wrap the path in [`staticFile()`](/docs/static-file), so it would be `staticFile("image.png")`.+This ensures that assets are loaded correctly if the webpage is not served on the root path `/`, which is the case on [Remotion Lambda](/docs/lambda) and [Remotion Cloud Run](/docs/cloudrun).++By using `staticFile()`, you can import assets from the public folder, and it will automatically also work in Remotion Studio as well as Remix, Vite, Next.js and Create React App in case you are using the [Remotion Player](/docs/player).++</details>++## Absolute paths are not portable++Before rendering a video, code is bundled to reduce the size of the assets that need to be sent to the browser. Your project with it's `node_modules` folder would be hundreds of megabytes large, but by bundling, the size is reduced drastically.++A bundle can also be uploaded and hosted on the internet, which is what [Remotion Lambda](/docs/lambda) and [Remotion Cloud Run](/docs/cloudrun) do and what is also possible using [regular rendering](/docs/terminology#serve-url).++Because the goal is to reduce the size of the bundle, only the `public` gets copied into the bundle.+Files with an absolute path would not be copied into the bundle, and therefore not be available when rendering on another device.++## Serving the filesystem via HTTP is dangerous++While Remotion could theoretically serve the full filesystem via HTTP so it is accessible via browser, this would be a security risk.+Any application or website could then read any file on your computer by making a HTTP request.++## What to do instead++### Use the `public` folder++Preferrably, copy files into the `public` folder and [`staticFile()`](/docs/staticfile) to [import assets](/docs/assets).++### Workaround: Use `npx serve`++Sometimes, it is preferrable to not copy all assets into your Remotion project because they are too large.++In this case, you can use [`npx serve`](https://www.npmjs.com/package/serve) to serve a folder on your computer via HTTP.++```bash+npx serve --cors C://Users/Joe/Documents+```++You will get a URL that you can use to access the folder via HTTP.+Pass URLs of assets to `<Img>`, `<Video>`, `<OffthreadVideo>`, `<Audio>`, `<Gif>` tags to use them in Remotion.++If you need to spawn a server programmatically, use [`serve-handler`](https://www.npmjs.com/package/serve-handler).++## See also++- [Importing assets](/docs/assets)diff --git a/packages/docs/docs/troubleshooting/bundling-bundle.md b/packages/docs/docs/troubleshooting/bundling-bundle.mdindex 65c72e5b52..f86032155c 100644--- a/packages/docs/docs/troubleshooting/bundling-bundle.md+++ b/packages/docs/docs/troubleshooting/bundling-bundle.md@@ -1,4 +1,5 @@---+image: /generated/articles-docs-troubleshooting-bundling-bundle.pngsidebar_label: Calling bundle() in bundled codetitle: Calling bundle() in bundled codecrumb: "FAQ"diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 53e1325f9d..14c61e84a9 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1476,6 +1476,13 @@ export const articles = [compId: "articles-docs-media-utils-index",crumb: null,},+ {+ id: "miscellaneous/absolute-paths",+ title: "Files with absolute paths",+ relativePath: "docs/miscellaneous/absolute-paths.md",+ compId: "articles-docs-miscellaneous-absolute-paths",+ crumb: "FAQ",+ },{id: "miscellaneous/automatic-duration",title: "Calculating the duration of a composition automatically",@@ -2647,6 +2654,13 @@ export const articles = [compId: "articles-docs-troubleshooting-broken-fast-refresh",crumb: "Troubleshooting",},+ {+ id: "troubleshooting/bundling-bundle",+ title: "Calling bundle() in bundled code",+ relativePath: "docs/troubleshooting/bundling-bundle.md",+ compId: "articles-docs-troubleshooting-bundling-bundle",+ crumb: "FAQ",+ },{id: "troubleshooting/could-not-be-parsed-as-a-value-list",title: "The source provided could not be parsed as a value list",diff --git a/packages/docs/static/generated/articles-docs-miscellaneous-absolute-paths.png b/packages/docs/static/generated/articles-docs-miscellaneous-absolute-paths.pngnew file mode 100644index 0000000000..48de5b851cBinary files /dev/null and b/packages/docs/static/generated/articles-docs-miscellaneous-absolute-paths.png differdiff --git a/packages/docs/static/generated/articles-docs-troubleshooting-bundling-bundle.png b/packages/docs/static/generated/articles-docs-troubleshooting-bundling-bundle.pngnew file mode 100644index 0000000000..f5393480bcBinary files /dev/null and b/packages/docs/static/generated/articles-docs-troubleshooting-bundling-bundle.png differ