🎥 Make videos programmatically with React
fix audio playback rates
Jonny Burger9b825e83d5a2
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex 7a41716702..0bc9a41374 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -354,7 +354,7 @@ export const Index: React.FC = () => {width={1080}height={1080}fps={30}- durationInFrames={500}+ durationInFrames={10000}/><Compositionid="skip-zero-frame"diff --git a/packages/lambda/src/test/integration/renders/slow-seamless-audio.bmp b/packages/lambda/src/test/integration/renders/slow-seamless-audio.bmpnew file mode 100644index 0000000000..aa3b771b97Binary files /dev/null and b/packages/lambda/src/test/integration/renders/slow-seamless-audio.bmp differdiff --git a/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts b/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.tsnew file mode 100644index 0000000000..1114f7662e--- /dev/null+++ b/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts@@ -0,0 +1,91 @@+import {RenderInternals} from '@remotion/renderer';+import {existsSync, unlinkSync} from 'fs';+import path from 'path';+import {afterAll, expect, test} from 'vitest';+import {deleteRender} from '../../../api/delete-render';+import {rendersPrefix} from '../../../defaults';+import {lambdaLs} from '../../../functions/helpers/io';+import {Wavedraw} from '../draw-wav';+import {simulateLambdaRender} from '../simulate-lambda-render';++afterAll(async () => {+ await RenderInternals.killAllBrowsers();+});++test('Should make slowed down seamless audio', async () => {+ const {close, file, progress, renderId} = await simulateLambdaRender({+ codec: 'aac',+ composition: 'framer',+ frameRange: [1750, 1790],+ imageFormat: 'none',+ logLevel: 'error',+ region: 'eu-central-1',+ inputProps: {playbackRate: 0.5},+ });++ const wav = path.join(process.cwd(), 'slow-seamless.wav');+ if (existsSync(wav)) {+ unlinkSync(wav);+ }++ await RenderInternals.callFf({+ bin: 'ffmpeg',+ args: ['-i', '-', '-ac', '1', '-c:a', 'pcm_s16le', '-y', wav],+ options: {+ stdin: file,+ },+ indent: false,+ binariesDirectory: null,+ cancelSignal: undefined,+ logLevel: 'info',+ });++ const wd = new Wavedraw(wav);++ const snapShot = path.join(__dirname, 'slow-seamless-audio.bmp');++ const options = {+ width: 600,+ height: 300,+ rms: true,+ maximums: true,+ average: false,+ start: 'START' as const,+ end: 'END' as const,+ colors: {+ maximums: '#0000ff',+ rms: '#659df7',+ background: '#ffffff',+ },+ filename: snapShot,+ };++ wd.drawWave(options); // outputs wave drawing to example1.png++ const files = await lambdaLs({+ bucketName: progress.outBucket as string,+ region: 'eu-central-1',+ expectedBucketOwner: 'abc',+ prefix: rendersPrefix(renderId),+ });++ expect(files.length).toBe(5);++ await deleteRender({+ bucketName: progress.outBucket as string,+ region: 'eu-central-1',+ renderId,+ });++ const expectFiles = await lambdaLs({+ bucketName: progress.outBucket as string,+ region: 'eu-central-1',+ expectedBucketOwner: 'abc',+ prefix: rendersPrefix(renderId),+ });++ expect(expectFiles.length).toBe(0);++ unlinkSync(wav);+ await close();+});diff --git a/packages/renderer/src/stringify-ffmpeg-filter.ts b/packages/renderer/src/stringify-ffmpeg-filter.tsindex 08633951f6..f60cc9c38b 100644--- a/packages/renderer/src/stringify-ffmpeg-filter.ts+++ b/packages/renderer/src/stringify-ffmpeg-filter.ts@@ -49,27 +49,32 @@ 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 =- (asset.trimLeft / fps + trimLeftOffset) / asset.playbackRate;- const trimRight =- trimLeft + (asset.duration / fps + trimRightOffset) / asset.playbackRate;+ const trimLeft = asset.trimLeft / fps + trimLeftOffset;+ const trimRight = trimLeft + (asset.duration / fps + trimRightOffset);const trimRightOrAssetDuration = assetDuration? Math.min(trimRight, assetDuration / asset.playbackRate): trimRight;- const actualTrimLeft = trimLeft * asset.playbackRate;- const actualTrimRight = trimRightOrAssetDuration * asset.playbackRate;+ if (trimRightOrAssetDuration < trimLeft) {+ throw new Error(+ 'trimRightOrAssetDuration < trimLeft: ' ++ JSON.stringify({+ trimRight,+ trimLeft,+ assetDuration,+ assetTrimLeft: asset.trimLeft,+ }),+ );+ }return {filter: [calculateATempo(asset.playbackRate),- `atrim=${stringifyTrim(actualTrimLeft)}:${stringifyTrim(- actualTrimRight,- )}`,+ `atrim=${stringifyTrim(trimLeft)}:${stringifyTrim(trimRight)}`,],- actualTrimLeft,- audibleDuration: actualTrimRight - actualTrimLeft,+ actualTrimLeft: trimLeft,+ audibleDuration: trimRight - trimLeft,};}@@ -130,7 +135,7 @@ export const stringifyFfmpegFilter = ({const startInVideoSeconds = startInVideo / fps;- if (assetDuration && (trimLeft / fps) * playbackRate >= assetDuration) {+ if (assetDuration && trimLeft / fps >= assetDuration / playbackRate) {return null;}