Skip to content

🎥 Make videos programmatically with React

remove ID from media asset, it's not necessary

Jonny Burgerd61c303ce6a3
diff --git a/packages/renderer/src/assets/calculate-asset-positions.ts b/packages/renderer/src/assets/calculate-asset-positions.ts
index 5598d5caf5..17cf2ffdc9 100644
--- a/packages/renderer/src/assets/calculate-asset-positions.ts
+++ b/packages/renderer/src/assets/calculate-asset-positions.ts
@@ -27,7 +27,6 @@ export const calculateAssetPositions = (frames: TAsset[][]): Assets => {
for (const asset of current) {
if (!findFrom(prev, asset)) {
assets.push({
- id: asset.id,
src: asset.src,
type: asset.type,
duration: null,
diff --git a/packages/renderer/src/assets/split-assets-into-segments.ts b/packages/renderer/src/assets/split-assets-into-segments.ts
index 9352207e22..2f641e130a 100644
--- a/packages/renderer/src/assets/split-assets-into-segments.ts
+++ b/packages/renderer/src/assets/split-assets-into-segments.ts
@@ -22,7 +22,7 @@ export const splitAssetsIntoSegments = ({
const sourcesAtThisTime = assets.filter((a) => {
return assetIsUsedAtTime(a, frame);
});
- return sourcesAtThisTime.map((s) => s.id).join(',');
+ return sourcesAtThisTime.map((s) => s.src).join(',');
});
const framesAtWhichToCut = [
0,
diff --git a/packages/renderer/src/assets/types.ts b/packages/renderer/src/assets/types.ts
index 6e5ac02572..8697880cdf 100644
--- a/packages/renderer/src/assets/types.ts
+++ b/packages/renderer/src/assets/types.ts
@@ -1,6 +1,6 @@
import {TAsset} from 'remotion';
-export type UnsafeAsset = Omit<TAsset, 'sequenceFrame'> & {
+export type UnsafeAsset = Omit<TAsset, 'sequenceFrame' | 'id'> & {
startInVideo: number;
duration: number | null;
trimLeft: number;
diff --git a/packages/renderer/src/test/asset-calculation.test.tsx b/packages/renderer/src/test/asset-calculation.test.tsx
index 48230ba2d9..f5c8331090 100644
--- a/packages/renderer/src/test/asset-calculation.test.tsx
+++ b/packages/renderer/src/test/asset-calculation.test.tsx
@@ -1,7 +1,6 @@
import React from 'react';
import {Audio, Sequence, useCurrentFrame, Video} from 'remotion';
import {calculateAssetPositions} from '../assets/calculate-asset-positions';
-import {MediaAsset} from '../assets/types';
import {getAssetsForMarkup} from './get-assets-for-markup';
const basicConfig = {
@@ -11,11 +10,6 @@ const basicConfig = {
durationInFrames: 60,
};
-const withoutId = (asset: MediaAsset) => {
- const {id, ...position} = asset;
- return position;
-};
-
const getPositions = async (Markup: React.FC) => {
const assets = await getAssetsForMarkup(Markup, basicConfig);
return calculateAssetPositions(assets);
@@ -26,7 +20,7 @@ test('Should be able to collect assets', async () => {
<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({
+ expect(assetPositions[0]).toEqual({
type: 'video',
src:
'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',
@@ -44,7 +38,7 @@ test('Should get multiple assets', async () => {
</div>
));
expect(assetPositions.length).toBe(2);
- expect(withoutId(assetPositions[0])).toEqual({
+ expect(assetPositions[0]).toEqual({
type: 'video',
src:
'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',
@@ -52,7 +46,7 @@ test('Should get multiple assets', async () => {
startInVideo: 0,
trimLeft: 0,
});
- expect(withoutId(assetPositions[1])).toEqual({
+ expect(assetPositions[1]).toEqual({
type: 'audio',
src:
'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp3',
@@ -74,7 +68,7 @@ test('Should handle jumps inbetween', async () => {
);
});
expect(assetPositions.length).toBe(2);
- expect(withoutId(assetPositions[0])).toEqual({
+ expect(assetPositions[0]).toEqual({
type: 'video',
src:
'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',
@@ -82,7 +76,7 @@ test('Should handle jumps inbetween', async () => {
startInVideo: 0,
trimLeft: 0,
});
- expect(withoutId(assetPositions[1])).toEqual({
+ expect(assetPositions[1]).toEqual({
type: 'video',
src:
'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',
@@ -101,7 +95,7 @@ test('Should support sequencing', async () => {
);
});
expect(assetPositions.length).toBe(1);
- expect(withoutId(assetPositions[0])).toEqual({
+ expect(assetPositions[0]).toEqual({
type: 'video',
src:
'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',
diff --git a/packages/renderer/src/test/asset-is-used-at-time.test.ts b/packages/renderer/src/test/asset-is-used-at-time.test.ts
index 5faffee0b6..25d4df1c90 100644
--- a/packages/renderer/src/test/asset-is-used-at-time.test.ts
+++ b/packages/renderer/src/test/asset-is-used-at-time.test.ts
@@ -5,7 +5,6 @@ test('Should give true is asset is used at time', () => {
assetIsUsedAtTime(
{
duration: 2,
- id: 'hi',
src: 'hi.mp4',
startInVideo: 0,
trimLeft: 2,
@@ -18,7 +17,6 @@ test('Should give true is asset is used at time', () => {
assetIsUsedAtTime(
{
duration: 2,
- id: 'hi',
src: 'hi.mp4',
startInVideo: 1,
trimLeft: 0,
@@ -34,7 +32,6 @@ test('Should give false if asset is not used at time', () => {
assetIsUsedAtTime(
{
duration: 2,
- id: 'hi',
src: 'hi.mp4',
startInVideo: 1,
trimLeft: 0,
@@ -47,7 +44,6 @@ test('Should give false if asset is not used at time', () => {
assetIsUsedAtTime(
{
duration: 2,
- id: 'hi',
src: 'hi.mp4',
startInVideo: 1,
trimLeft: 0,
diff --git a/packages/renderer/src/test/ffmpeg-filters.test.ts b/packages/renderer/src/test/ffmpeg-filters.test.ts
index d2c51f0741..3151699f07 100644
--- a/packages/renderer/src/test/ffmpeg-filters.test.ts
+++ b/packages/renderer/src/test/ffmpeg-filters.test.ts
@@ -11,7 +11,6 @@ const asset: MediaAsset = {
duration: 20,
startInVideo: 0,
trimLeft: 0,
- id: String(0.1),
};
test('Should create a basic filter correctly', () => {
diff --git a/packages/renderer/src/test/split-assets-into-segments.test.tsx b/packages/renderer/src/test/split-assets-into-segments.test.tsx
index 1c7f9074a4..0614aac1f3 100644
--- a/packages/renderer/src/test/split-assets-into-segments.test.tsx
+++ b/packages/renderer/src/test/split-assets-into-segments.test.tsx
@@ -6,7 +6,6 @@ test('Should create segments of audio clips correctly', () => {
// Clip from 0-10 seconds
{
duration: 300,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -15,7 +14,6 @@ test('Should create segments of audio clips correctly', () => {
// Clip from 5-15 seconds
{
duration: 300,
- id: '0.2',
src: 'asset2.mp4',
startInVideo: 150,
trimLeft: 0,
@@ -25,7 +23,6 @@ test('Should create segments of audio clips correctly', () => {
expect(splitAssetsIntoSegments({assets, duration: 450})).toEqual([
{
duration: 150,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -33,7 +30,6 @@ test('Should create segments of audio clips correctly', () => {
},
{
duration: 150,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 150,
trimLeft: 150,
@@ -41,7 +37,6 @@ test('Should create segments of audio clips correctly', () => {
},
{
duration: 150,
- id: '0.2',
src: 'asset2.mp4',
startInVideo: 150,
trimLeft: 0,
@@ -49,7 +44,6 @@ test('Should create segments of audio clips correctly', () => {
},
{
duration: 150,
- id: '0.2',
src: 'asset2.mp4',
startInVideo: 300,
trimLeft: 150,
@@ -63,7 +57,6 @@ test('Should leave single clip untouched', () => {
// Clip from 0-10 seconds
{
duration: 300,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -73,7 +66,6 @@ test('Should leave single clip untouched', () => {
expect(splitAssetsIntoSegments({assets, duration: 450})).toEqual([
{
duration: 300,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -87,7 +79,6 @@ test('Should leave two identical clips the same', () => {
// Clip from 0-10 seconds
{
duration: 300,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -95,7 +86,6 @@ test('Should leave two identical clips the same', () => {
},
{
duration: 300,
- id: '0.2',
src: 'asset2.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -105,7 +95,6 @@ test('Should leave two identical clips the same', () => {
expect(splitAssetsIntoSegments({assets, duration: 450})).toEqual([
{
duration: 300,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -113,7 +102,6 @@ test('Should leave two identical clips the same', () => {
},
{
duration: 300,
- id: '0.2',
src: 'asset2.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -127,7 +115,6 @@ test('Should not have one-off errors', () => {
// Clip from 0-10 seconds
{
duration: 2,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -135,7 +122,6 @@ test('Should not have one-off errors', () => {
},
{
duration: 2,
- id: '0.2',
src: 'asset2.mp4',
startInVideo: 1,
trimLeft: 0,
@@ -143,7 +129,6 @@ test('Should not have one-off errors', () => {
},
{
duration: 2,
- id: '0.3',
src: 'asset3.mp4',
startInVideo: 2,
trimLeft: 0,
@@ -153,7 +138,6 @@ test('Should not have one-off errors', () => {
expect(splitAssetsIntoSegments({assets, duration: 450})).toEqual([
{
duration: 1,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 0,
trimLeft: 0,
@@ -161,7 +145,6 @@ test('Should not have one-off errors', () => {
},
{
duration: 1,
- id: '0.1',
src: 'asset1.mp4',
startInVideo: 1,
trimLeft: 1,
@@ -169,7 +152,6 @@ test('Should not have one-off errors', () => {
},
{
duration: 1,
- id: '0.2',
src: 'asset2.mp4',
startInVideo: 1,
trimLeft: 0,
@@ -177,7 +159,6 @@ test('Should not have one-off errors', () => {
},
{
duration: 1,
- id: '0.2',
src: 'asset2.mp4',
startInVideo: 2,
trimLeft: 1,
@@ -185,7 +166,6 @@ test('Should not have one-off errors', () => {
},
{
duration: 1,
- id: '0.3',
src: 'asset3.mp4',
startInVideo: 2,
trimLeft: 0,
@@ -193,7 +173,6 @@ test('Should not have one-off errors', () => {
},
{
duration: 1,
- id: '0.3',
src: 'asset3.mp4',
startInVideo: 3,
trimLeft: 1,