Skip to content

🎥 Make videos programmatically with React

fix algo

Jonny Burger91b4097f0afd
diff --git a/packages/lambda/src/test/integration/renders/regular-audio.bmp b/packages/lambda/src/test/integration/renders/regular-audio.bmp
index bf298b0199..9960764c3a 100644
Binary files a/packages/lambda/src/test/integration/renders/regular-audio.bmp and b/packages/lambda/src/test/integration/renders/regular-audio.bmp differ
diff --git a/packages/lambda/src/test/integration/renders/slow-seamless-audio.bmp b/packages/lambda/src/test/integration/renders/slow-seamless-audio.bmp
index aa3b771b97..63e1cec058 100644
Binary files a/packages/lambda/src/test/integration/renders/slow-seamless-audio.bmp and b/packages/lambda/src/test/integration/renders/slow-seamless-audio.bmp differ
diff --git a/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts b/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts
index 1114f7662e..04d26a4921 100644
--- a/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts
+++ b/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts
@@ -16,7 +16,7 @@ test('Should make slowed down seamless audio', async () => {
const {close, file, progress, renderId} = await simulateLambdaRender({
codec: 'aac',
composition: 'framer',
- frameRange: [1750, 1790],
+ frameRange: [1700, 1740],
imageFormat: 'none',
logLevel: 'error',
region: 'eu-central-1',
diff --git a/packages/lambda/src/test/integration/webhooks.test.ts b/packages/lambda/src/test/integration/webhooks.test.ts
index 6e08656fb5..cd6f94b444 100644
--- a/packages/lambda/src/test/integration/webhooks.test.ts
+++ b/packages/lambda/src/test/integration/webhooks.test.ts
@@ -1,4 +1,5 @@
import {RenderInternals} from '@remotion/renderer';
+import path from 'path';
import {VERSION} from 'remotion/version';
import {beforeAll, beforeEach, describe, expect, test, vi} from 'vitest';
import {LambdaRoutines} from '../../defaults';
@@ -41,11 +42,24 @@ describe('Webhooks', () => {
process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '2048';
process.env.AWS_LAMBDA_FUNCTION_NAME = 'remotion-dev-lambda';
+ const exampleBuild = path.join(process.cwd(), '..', 'example', 'build');
+
+ const {port, close} = await RenderInternals.serveStatic(exampleBuild, {
+ binariesDirectory: null,
+ concurrency: 1,
+ downloadMap: RenderInternals.makeDownloadMap(),
+ indent: false,
+ logLevel: 'error',
+ offthreadVideoCacheSizeInBytes: null,
+ port: null,
+ remotionRoot: path.dirname(exampleBuild),
+ forceIPv4: false,
+ });
+
const res = await callLambda({
type: LambdaRoutines.start,
payload: {
- serveUrl:
- 'https://64d3734a6bb69052c34d3616--spiffy-kelpie-71657b.netlify.app/',
+ serveUrl: `http://localhost:${port}`,
chromiumOptions: {},
codec: 'h264',
composition: 'react-svg',
@@ -137,11 +151,27 @@ describe('Webhooks', () => {
},
expect.anything(),
);
+ await close();
});
test('Should call webhook upon timeout', async () => {
process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '2048';
+ const exampleBuild = path.join(process.cwd(), '..', 'example', 'build');
+
+ // Maybe this can use simulateLambdaRender instead
+ const {port, close} = await RenderInternals.serveStatic(exampleBuild, {
+ binariesDirectory: null,
+ concurrency: 1,
+ downloadMap: RenderInternals.makeDownloadMap(),
+ indent: false,
+ logLevel: 'error',
+ offthreadVideoCacheSizeInBytes: null,
+ port: null,
+ remotionRoot: path.dirname(exampleBuild),
+ forceIPv4: false,
+ });
+
await callLambda({
functionName: 'remotion-dev-lambda',
receivedStreamingPayload: () => undefined,
@@ -149,8 +179,7 @@ describe('Webhooks', () => {
type: LambdaRoutines.launch,
payload: {
offthreadVideoCacheSizeInBytes: null,
- serveUrl:
- 'https://64d3734a6bb69052c34d3616--spiffy-kelpie-71657b.netlify.app/',
+ serveUrl: `http://localhost:${port}`,
chromiumOptions: {},
codec: 'h264',
composition: 'react-svg',
@@ -223,5 +252,6 @@ describe('Webhooks', () => {
},
expect.anything(),
);
+ await close();
});
});
diff --git a/packages/renderer/src/stringify-ffmpeg-filter.ts b/packages/renderer/src/stringify-ffmpeg-filter.ts
index ed990ff684..d0d67a1d1b 100644
--- a/packages/renderer/src/stringify-ffmpeg-filter.ts
+++ b/packages/renderer/src/stringify-ffmpeg-filter.ts
@@ -29,18 +29,31 @@ export const getActualTrimLeft = ({
asset,
fps,
trimLeftOffset,
+ seamless,
}: {
asset: MediaAsset;
fps: number;
trimLeftOffset: number;
+ seamless: boolean;
}) => {
const sinceStart = asset.trimLeft - asset.audioStartFrame;
+ if (!seamless) {
+ return (
+ asset.audioStartFrame / fps +
+ (sinceStart / fps) * asset.playbackRate +
+ trimLeftOffset
+ );
+ }
+
+ if (seamless) {
+ return (
+ asset.audioStartFrame / fps / asset.playbackRate +
+ sinceStart / fps +
+ trimLeftOffset
+ );
+ }
- return (
- asset.audioStartFrame / fps / asset.playbackRate +
- sinceStart / fps +
- trimLeftOffset
- );
+ throw new Error('This should never happen');
};
const trimAndSetTempo = ({
@@ -67,7 +80,12 @@ const trimAndSetTempo = ({
// and the offset needs to be the same for all audio tracks, before processing it further.
// This also affects the trimLeft and trimRight values, as they need to be adjusted.
if (forSeamlessAacConcatenation) {
- const trimLeft = getActualTrimLeft({asset, fps, trimLeftOffset});
+ const trimLeft = getActualTrimLeft({
+ asset,
+ fps,
+ trimLeftOffset,
+ seamless: true,
+ });
const trimRight =
trimLeft + asset.duration / fps - trimLeftOffset + trimRightOffset;
@@ -104,6 +122,7 @@ const trimAndSetTempo = ({
asset,
fps,
trimLeftOffset,
+ seamless: false,
});
const trimRight =
actualTrimLeft + (asset.duration / fps) * asset.playbackRate;
@@ -163,6 +182,7 @@ export const stringifyFfmpegFilter = ({
asset,
fps,
trimLeftOffset,
+ seamless: forSeamlessAacConcatenation,
}) >=
assetDuration / playbackRate
) {