Skip to content

🎥 Make videos programmatically with React

remove sequenceFrame from processed assets

Jonny Burger519508665e92
diff --git a/packages/example/src/AudioTestingMute/index.tsx b/packages/example/src/AudioTestingMute/index.tsx
index ef727883b1..7ff20eedc5 100644
--- a/packages/example/src/AudioTestingMute/index.tsx
+++ b/packages/example/src/AudioTestingMute/index.tsx
@@ -11,7 +11,7 @@ import movie from '../resources/framer-music.mp4';
import music from '../resources/sound1.mp3';
const AudioTestingMute: React.FC = () => {
- const sequenceFrame = useCurrentFrame();
+ const frame = useCurrentFrame();
const {durationInFrames, fps} = useVideoConfig();
/**
@@ -25,11 +25,11 @@ const AudioTestingMute: React.FC = () => {
{start: 4 * fps, end: 5 * fps},
];
const toMute = muteParts.some(
- (mp) => sequenceFrame >= mp.start && sequenceFrame <= mp.end
+ (mp) => frame >= mp.start && frame <= mp.end
);
return type == 'movie' ? toMute : !toMute;
},
- [fps, sequenceFrame]
+ [fps, frame]
);
return (
diff --git a/packages/renderer/src/assets/calculate-asset-positions.ts b/packages/renderer/src/assets/calculate-asset-positions.ts
index e127bfd424..ec161dda1f 100644
--- a/packages/renderer/src/assets/calculate-asset-positions.ts
+++ b/packages/renderer/src/assets/calculate-asset-positions.ts
@@ -26,7 +26,9 @@ export const calculateAssetPositions = (frames: TAsset[][]): Assets => {
for (const asset of current) {
if (!findFrom(prev, asset)) {
assets.push({
- ...asset,
+ id: asset.id,
+ src: asset.src,
+ type: asset.type,
duration: null,
startInVideo: frame,
});
diff --git a/packages/renderer/src/assets/types.ts b/packages/renderer/src/assets/types.ts
index de97142881..62ef8779b1 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 = TAsset & {
+export type UnsafeAsset = Omit<TAsset, 'sequenceFrame'> & {
startInVideo: number;
duration: number | null;
};
diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.ts
index 4b6b7b65a3..459561fd6a 100644
--- a/packages/renderer/src/stitcher.ts
+++ b/packages/renderer/src/stitcher.ts
@@ -80,9 +80,9 @@ export const stitchFramesToVideo = async (options: {
const filters = assetPositions
.map((asset, i) => {
const duration = (asset.duration / options.fps).toFixed(3); // in seconds with milliseconds level precision
- const assetTrimLeft = (asset.sequenceFrame / options.fps).toFixed(3);
+ const assetTrimLeft = (asset.startInVideo / options.fps).toFixed(3);
const assetTrimRight = (
- (asset.sequenceFrame + asset.duration) /
+ (asset.startInVideo + asset.duration) /
options.fps
).toFixed(3);
const startInVideo = (
diff --git a/packages/renderer/src/test/asset-calculation.test.tsx b/packages/renderer/src/test/asset-calculation.test.tsx
index 8906295838..ea0038a75e 100644
--- a/packages/renderer/src/test/asset-calculation.test.tsx
+++ b/packages/renderer/src/test/asset-calculation.test.tsx
@@ -1,6 +1,7 @@
import React from 'react';
-import {Audio, TAsset, Video} from 'remotion';
+import {Audio, 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 = {
@@ -10,7 +11,7 @@ const basicConfig = {
durationInFrames: 60,
};
-const withoutId = (asset: TAsset) => {
+const withoutId = (asset: MediaAsset) => {
const {id, ...position} = asset;
return position;
};
@@ -29,7 +30,6 @@ test('Should be able to collect assets', async () => {
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,
});
@@ -47,7 +47,6 @@ test('Should get multiple assets', async () => {
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,
});
@@ -55,8 +54,35 @@ test('Should get multiple assets', async () => {
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,
});
});
+
+test('Should handle jumps inbetween', async () => {
+ const assetPositions = await getPositions(() => {
+ const frame = useCurrentFrame();
+ return (
+ <div>
+ {frame !== 20 ? (
+ <Video src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" />
+ ) : null}
+ </div>
+ );
+ });
+ 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',
+ duration: 20,
+ startInVideo: 0,
+ });
+ expect(withoutId(assetPositions[1])).toEqual({
+ type: 'video',
+ src:
+ 'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',
+ duration: 39,
+ startInVideo: 21,
+ });
+});