Skip to content

🎥 Make videos programmatically with React

refine

Jonny Burger12f194cb496a
diff --git a/packages/renderer/src/test/asset-calculation.test.tsx b/packages/renderer/src/test/asset-calculation.test.tsx
index 3b1c273ba2..8906295838 100644
--- a/packages/renderer/src/test/asset-calculation.test.tsx
+++ b/packages/renderer/src/test/asset-calculation.test.tsx
@@ -1,25 +1,49 @@
import React from 'react';
-import {Video} from 'remotion';
+import {Audio, TAsset, Video} from 'remotion';
import {calculateAssetPositions} from '../assets/calculate-asset-positions';
import {getAssetsForMarkup} from './get-assets-for-markup';
+const basicConfig = {
+ width: 1080,
+ height: 1080,
+ fps: 30,
+ durationInFrames: 60,
+};
+
+const withoutId = (asset: TAsset) => {
+ const {id, ...position} = asset;
+ return position;
+};
+
+const getPositions = async (Markup: React.FC) => {
+ const assets = await getAssetsForMarkup(Markup, basicConfig);
+ return calculateAssetPositions(assets);
+};
+
test('Should be able to collect assets', async () => {
- const Markup: React.FC = () => (
+ const assetPositions = await getPositions(() => (
+ <Video src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" />
+ ));
+ expect(assetPositions.length).toBe(1);
+ expect(withoutId(assetPositions[0])).toEqual({
+ type: 'video',
+ src:
+ 'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',
+ sequenceFrame: 0,
+ duration: 60,
+ startInVideo: 0,
+ });
+});
+
+test('Should get multiple assets', async () => {
+ const assetPositions = await getPositions(() => (
<div>
<Video src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" />
+ <Audio src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp3" />
</div>
- );
- const assets = await getAssetsForMarkup(Markup, {
- width: 1080,
- height: 1080,
- fps: 30,
- durationInFrames: 60,
- });
- const assetPositions = calculateAssetPositions(assets);
- expect(assetPositions.length).toBe(1);
- const firstPosition = assetPositions[0];
- const {id, ...position} = firstPosition;
- expect(position).toEqual({
+ ));
+ expect(assetPositions.length).toBe(2);
+ expect(withoutId(assetPositions[0])).toEqual({
type: 'video',
src:
'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',
@@ -27,4 +51,12 @@ test('Should be able to collect assets', async () => {
duration: 60,
startInVideo: 0,
});
+ expect(withoutId(assetPositions[1])).toEqual({
+ type: 'audio',
+ src:
+ 'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp3',
+ sequenceFrame: 0,
+ duration: 60,
+ startInVideo: 0,
+ });
});
diff --git a/packages/renderer/src/test/get-assets-for-markup.tsx b/packages/renderer/src/test/get-assets-for-markup.tsx
index a0df4c8306..8267968ded 100644
--- a/packages/renderer/src/test/get-assets-for-markup.tsx
+++ b/packages/renderer/src/test/get-assets-for-markup.tsx
@@ -14,7 +14,7 @@ const waitForWindowToBeReady = () => {
resolve();
}
};
- interval = setInterval(check, 10);
+ interval = setInterval(check, 5);
});
};
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 cf481ba52d..09700e331c 100644
--- a/packages/renderer/src/test/map-localhost-to-file.test.ts
+++ b/packages/renderer/src/test/map-localhost-to-file.test.ts
@@ -1,4 +1,5 @@
import {downloadAndMapAssetsToFileUrl} from '../assets/download-and-map-assets-to-file';
+import {fileNameInOs} from './os-file';
test('Should correctly map a localhost URL to an asset', async () => {
expect(
@@ -14,8 +15,9 @@ test('Should correctly map a localhost URL to an asset', async () => {
})
).toEqual({
type: 'video',
- src:
- '/var/folders/hl/p8pg9kw15dbg3l7dbpn0scc80000gn/T/react-motion-graphicstoSTC7/5f25ba62771d1f8195f858ec5ff8e8d6.mp4',
+ src: fileNameInOs(
+ '/var/folders/hl/p8pg9kw15dbg3l7dbpn0scc80000gn/T/react-motion-graphicstoSTC7/5f25ba62771d1f8195f858ec5ff8e8d6.mp4'
+ ),
id: '0.8331499681195862',
sequenceFrame: 2045,
});
diff --git a/packages/renderer/src/test/os-file.ts b/packages/renderer/src/test/os-file.ts
new file mode 100644
index 0000000000..5df24dfd11
--- /dev/null
+++ b/packages/renderer/src/test/os-file.ts
@@ -0,0 +1,6 @@
+export const fileNameInOs = (filename: string) => {
+ if (process.platform === 'win32') {
+ return filename.replace(/\//g, '\\');
+ }
+ return filename;
+};