Skip to content

🎥 Make videos programmatically with React

bundle dir

Jonny Burgerb82acf273a30
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 836a5a89b9..12487d2d98 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -198,6 +198,7 @@ export const render = async () => {
frameRange: frameRange ?? null,
puppeteerInstance: openedBrowser,
serveUrl,
+ bundleDir: bundled,
});
const closeBrowserPromise = openedBrowser.close();
diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsx
index fd287e12f4..0de96dff17 100644
--- a/packages/core/src/CompositionManager.tsx
+++ b/packages/core/src/CompositionManager.tsx
@@ -64,6 +64,7 @@ export type TAsset = {
export type RenderAssetInfo = {
assets: TAsset[][];
+ bundleDir: string | null;
};
export type CompositionManagerContext = {
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index cfb29f99a2..95a9e5e04e 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -40,7 +40,8 @@ const matchCommand = async () => {
};
export const cli = async () => {
- CliInternals.loadConfigFile(CliInternals.getConfigFileName());
+ // TODO: TS hardcoded, support JS just as in normal CLI
+ CliInternals.loadConfigFile(CliInternals.getConfigFileName(false), false);
try {
await matchCommand();
} catch (err) {
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 8e1d288ebf..92d80c8ea5 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -81,6 +81,7 @@ const renderHandler = async (params: LambdaPayload) => {
outputDir,
puppeteerInstance: browserInstance,
serveUrl: params.serveUrl,
+ bundleDir: null,
});
const condensedTimingData: ChunkTimingData = {
...chunkTimingData,
diff --git a/packages/renderer/src/assets/convert-assets-to-file-urls.ts b/packages/renderer/src/assets/convert-assets-to-file-urls.ts
index 959cb78993..91bb11a1a5 100644
--- a/packages/renderer/src/assets/convert-assets-to-file-urls.ts
+++ b/packages/renderer/src/assets/convert-assets-to-file-urls.ts
@@ -13,10 +13,12 @@ export const convertAssetsToFileUrls = async ({
assets,
downloadDir,
onDownload,
+ webpackBundle,
}: {
assets: TAsset[][];
downloadDir: string;
onDownload: (src: string) => void;
+ webpackBundle: string | null;
}): Promise<TAsset[][]> => {
const chunks = chunk(assets, 1000);
const results: TAsset[][][] = [];
@@ -30,6 +32,7 @@ export const convertAssetsToFileUrls = async ({
localhostAsset: a,
downloadDir,
onDownload,
+ webpackBundle,
});
})
);
diff --git a/packages/renderer/src/assets/download-and-map-assets-to-file.ts b/packages/renderer/src/assets/download-and-map-assets-to-file.ts
index 7bf8aab1ed..327c317490 100644
--- a/packages/renderer/src/assets/download-and-map-assets-to-file.ts
+++ b/packages/renderer/src/assets/download-and-map-assets-to-file.ts
@@ -78,14 +78,20 @@ export const getSanitizedFilenameForAssetUrl = ({
src,
isRemote,
webpackBundle,
+ downloadDir,
}: {
src: string;
isRemote: boolean;
- webpackBundle: string;
+ webpackBundle: string | null;
+ downloadDir: string;
}) => {
const {pathname, search} = new URL(src);
if (!isRemote) {
+ if (!webpackBundle) {
+ throw new TypeError('Expected webpack bundle');
+ }
+
return path.join(webpackBundle, sanitizeFilename(pathname));
}
@@ -99,7 +105,7 @@ export const getSanitizedFilenameForAssetUrl = ({
''
);
return path.join(
- webpackBundle,
+ downloadDir,
sanitizeFilename(hashedFileName + fileExtension)
);
};
@@ -108,15 +114,18 @@ export const downloadAndMapAssetsToFileUrl = async ({
localhostAsset,
downloadDir,
onDownload,
+ webpackBundle,
}: {
localhostAsset: TAsset;
downloadDir: string;
onDownload: (src: string) => void;
+ webpackBundle: string | null;
}): Promise<TAsset> => {
const newSrc = getSanitizedFilenameForAssetUrl({
src: localhostAsset.src,
isRemote: localhostAsset.isRemote,
- webpackBundle: downloadDir,
+ webpackBundle,
+ downloadDir,
});
if (localhostAsset.isRemote) {
diff --git a/packages/renderer/src/render.ts b/packages/renderer/src/render.ts
index 1a715872d9..9f22d545ca 100644
--- a/packages/renderer/src/render.ts
+++ b/packages/renderer/src/render.ts
@@ -43,6 +43,7 @@ export const renderFrames = async ({
serveUrl,
onError,
envVariables,
+ bundleDir,
}: {
config: VideoConfig;
compositionId: string;
@@ -61,6 +62,8 @@ export const renderFrames = async ({
browser?: Browser;
frameRange?: FrameRange | null;
serveUrl: string;
+ // TODO: It's just pass through but not really needed
+ bundleDir: string | null;
dumpBrowserLogs?: boolean;
puppeteerInstance: PuppeteerBrowser;
onError?: (info: OnErrorInfo) => void;
@@ -189,6 +192,7 @@ export const renderFrames = async ({
return {
assetsInfo: {
assets,
+ bundleDir,
},
frameCount,
};
diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.ts
index 449cc09a48..56a5cd1e42 100644
--- a/packages/renderer/src/stitcher.ts
+++ b/packages/renderer/src/stitcher.ts
@@ -26,7 +26,7 @@ import {resolveAssetSrc} from './resolve-asset-src';
import {validateFfmpeg} from './validate-ffmpeg';
const makeAssetsDownloadTmpDir = (): Promise<string> => {
- return fs.promises.mkdtemp(path.join(os.tmpdir(), 'remotion-complex-filter'));
+ return fs.promises.mkdtemp(path.join(os.tmpdir(), 'remotion-assets-dir'));
};
// eslint-disable-next-line complexity
@@ -105,6 +105,7 @@ export const stitchFramesToVideo = async (options: {
assets: options.assetsInfo.assets,
downloadDir: options.downloadDir ?? (await makeAssetsDownloadTmpDir()),
onDownload: options.onDownload ?? (() => undefined),
+ webpackBundle: options.assetsInfo.bundleDir,
}),
]);
@@ -146,7 +147,7 @@ export const stitchFramesToVideo = async (options: {
frameInfo
? ['-i', `element-%0${frameInfo.numberLength}d.${imageFormat}`]
: null,
- ...assetPaths.map((path) => ['-i', path]),
+ ...assetPaths.map((p) => ['-i', p]),
encoderName
? // -c:v is the same as -vcodec as -codec:video
// and specified the video codec.
diff --git a/packages/renderer/src/test/handle-weird-file-names.test.ts b/packages/renderer/src/test/handle-weird-file-names.test.ts
index 246db5816e..760e836326 100644
--- a/packages/renderer/src/test/handle-weird-file-names.test.ts
+++ b/packages/renderer/src/test/handle-weird-file-names.test.ts
@@ -4,6 +4,7 @@ test('Should sanitize weird file names when downloading', async () => {
const newSrc = getSanitizedFilenameForAssetUrl({
src: 'http://gtts-api.miniggiodev.fr/Ici+Japon+Corp.?lang=ja',
isRemote: true,
+ downloadDir: '',
webpackBundle: '/var/tmp',
});
expect(newSrc).toBe(
@@ -17,16 +18,19 @@ test('Should give different file names based on different url query parameters',
const asset1 = getSanitizedFilenameForAssetUrl({
src: 'https://gtts-api.miniggiodev.fr/Ici+Japon+Corp.mp4?hi=1',
isRemote: true,
+ downloadDir: '',
webpackBundle: '/var/tmp',
});
const sameAgain = getSanitizedFilenameForAssetUrl({
src: 'https://gtts-api.miniggiodev.fr/Ici+Japon+Corp.mp4?hi=1',
isRemote: true,
+ downloadDir: '',
webpackBundle: '/var/tmp',
});
const differentAsset = getSanitizedFilenameForAssetUrl({
src: 'https://gtts-api.miniggiodev.fr/Ici+Japon+Corp.mp4?hi=2',
isRemote: true,
+ downloadDir: '',
webpackBundle: '/var/tmp',
});
expect(asset1).toEqual(sameAgain);
diff --git a/packages/renderer/src/test/map-localhost-to-file.test.ts b/packages/renderer/src/test/map-localhost-to-file.test.ts
index 70dc82ef5e..4adbe076cd 100644
--- a/packages/renderer/src/test/map-localhost-to-file.test.ts
+++ b/packages/renderer/src/test/map-localhost-to-file.test.ts
@@ -15,6 +15,7 @@ test('Should correctly map a localhost URL to an asset', async () => {
playbackRate: 1,
},
onDownload: () => undefined,
+ webpackBundle: null,
downloadDir:
'/var/folders/hl/p8pg9kw15dbg3l7dbpn0scc80000gn/T/react-motion-graphicstoSTC7',
})