🎥 Make videos programmatically with React
add sequenceframe back as trimLet
Jonny Burgerd5fde74ff279
diff --git a/packages/renderer/src/assets/calculate-asset-positions.ts b/packages/renderer/src/assets/calculate-asset-positions.tsindex ec161dda1f..eccb84ab6c 100644--- a/packages/renderer/src/assets/calculate-asset-positions.ts+++ b/packages/renderer/src/assets/calculate-asset-positions.ts@@ -31,6 +31,7 @@ export const calculateAssetPositions = (frames: TAsset[][]): Assets => {type: asset.type,duration: null,startInVideo: frame,+ trimLeft: asset.sequenceFrame,});}diff --git a/packages/renderer/src/assets/types.ts b/packages/renderer/src/assets/types.tsindex 62ef8779b1..6e5ac02572 100644--- a/packages/renderer/src/assets/types.ts+++ b/packages/renderer/src/assets/types.ts@@ -3,6 +3,7 @@ import {TAsset} from 'remotion';export type UnsafeAsset = Omit<TAsset, 'sequenceFrame'> & {startInVideo: number;duration: number | null;+ trimLeft: number;};export type MediaAsset = Omit<UnsafeAsset, 'duration'> & {diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.tsindex 459561fd6a..3e98066073 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.startInVideo / options.fps).toFixed(3);+ const assetTrimLeft = (asset.trimLeft / options.fps).toFixed(3);const assetTrimRight = (- (asset.startInVideo + asset.duration) /+ (asset.trimLeft + 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.tsxindex ea0038a75e..48230ba2d9 100644--- a/packages/renderer/src/test/asset-calculation.test.tsx+++ b/packages/renderer/src/test/asset-calculation.test.tsx@@ -1,5 +1,5 @@import React from 'react';-import {Audio, useCurrentFrame, Video} from 'remotion';+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';@@ -32,6 +32,7 @@ test('Should be able to collect assets', async () => {'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',duration: 60,startInVideo: 0,+ trimLeft: 0,});});@@ -49,6 +50,7 @@ test('Should get multiple assets', async () => {'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',duration: 60,startInVideo: 0,+ trimLeft: 0,});expect(withoutId(assetPositions[1])).toEqual({type: 'audio',@@ -56,6 +58,7 @@ test('Should get multiple assets', async () => {'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp3',duration: 60,startInVideo: 0,+ trimLeft: 0,});});@@ -77,6 +80,7 @@ test('Should handle jumps inbetween', async () => {'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',duration: 20,startInVideo: 0,+ trimLeft: 0,});expect(withoutId(assetPositions[1])).toEqual({type: 'video',@@ -84,5 +88,25 @@ test('Should handle jumps inbetween', async () => {'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4',duration: 39,startInVideo: 21,+ trimLeft: 21,+ });+});++test('Should support sequencing', async () => {+ const assetPositions = await getPositions(() => {+ return (+ <Sequence durationInFrames={30} from={-20}>+ <Video src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" />+ </Sequence>+ );+ });+ 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',+ duration: 10,+ startInVideo: 0,+ trimLeft: 20,});});