🎥 Make videos programmatically with React
new `forSeamlessAacConcatenation` flag
Jonny Burger4d3037f1c03b
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex 6a3682dc6e..d0f3ce1c44 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -461,6 +461,7 @@ export const benchmarkCommand = async (}).value,finishRenderProgress: () => undefined,separateAudioTo: null,+ forSeamlessAacConcatentation: false,},(run, progress) => {benchmarkProgress.update(diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.tsindex 5714f6bba2..8e10a9ba44 100644--- a/packages/cli/src/render-flows/render.ts+++ b/packages/cli/src/render-flows/render.ts@@ -519,6 +519,7 @@ export const renderVideoFlow = async ({},binariesDirectory,separateAudioTo: null,+ forSeamlessAacConcatentation: false,});Log.info(diff --git a/packages/cloudrun/src/functions/render-media-single-thread.ts b/packages/cloudrun/src/functions/render-media-single-thread.tsindex 76fecdf750..2a81d9b3a2 100644--- a/packages/cloudrun/src/functions/render-media-single-thread.ts+++ b/packages/cloudrun/src/functions/render-media-single-thread.ts@@ -122,6 +122,7 @@ export const renderMediaSingleThread = async (finishRenderProgress: () => undefined,binariesDirectory: null,separateAudioTo: null,+ forSeamlessAacConcatentation: false,});const storage = new Storage();diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.tsindex 7d189df208..e1d591147d 100644--- a/packages/lambda/src/functions/renderer.ts+++ b/packages/lambda/src/functions/renderer.ts@@ -239,6 +239,7 @@ const renderHandler = async (finishRenderProgress: () => undefined,binariesDirectory: null,separateAudioTo: audioOutputLocation,+ forSeamlessAacConcatentation: seamless,}).then(({slowestFrames}) => {console.log(`Slowest frames:`);diff --git a/packages/renderer/src/calculate-ffmpeg-filters.ts b/packages/renderer/src/calculate-ffmpeg-filters.tsindex 029e523564..ebe1a1105c 100644--- a/packages/renderer/src/calculate-ffmpeg-filters.ts+++ b/packages/renderer/src/calculate-ffmpeg-filters.ts@@ -11,32 +11,37 @@ export const calculateFfmpegFilter = ({durationInFrames,channels,assetDuration,+ forSeamlessAacConcatentation,}: {asset: MediaAsset;fps: number;durationInFrames: number;channels: number;assetDuration: number | null;+ forSeamlessAacConcatentation: boolean;}): FilterWithoutPaddingApplied | null => {if (channels === 0) {return null;}- const assetTrimLeft = Math.max(- 0,- getClosestAlignedTime(- ((asset.trimLeft * asset.playbackRate) / fps) * 1_000_000,- ) /- 1_000_000 -- 2 * (1024 / DEFAULT_SAMPLE_RATE),- );- const assetTrimRight =- getClosestAlignedTime(- ((asset.trimLeft + asset.duration * asset.playbackRate) / fps) *- 1_000_000,- ) /- 1_000_000 +- 2 * (1024 / DEFAULT_SAMPLE_RATE);+ const assetTrimLeft = forSeamlessAacConcatentation+ ? Math.max(+ 0,+ getClosestAlignedTime(+ ((asset.trimLeft * asset.playbackRate) / fps) * 1_000_000,+ ) /+ 1_000_000 -+ 2 * (1024 / DEFAULT_SAMPLE_RATE),+ )+ : (asset.trimLeft * asset.playbackRate) / fps;+ const assetTrimRight = forSeamlessAacConcatentation+ ? getClosestAlignedTime(+ ((asset.trimLeft + asset.duration * asset.playbackRate) / fps) *+ 1_000_000,+ ) /+ 1_000_000 ++ 2 * (1024 / DEFAULT_SAMPLE_RATE)+ : assetTrimLeft + (asset.duration * asset.playbackRate) / fps;return stringifyFfmpegFilter({channels,diff --git a/packages/renderer/src/create-audio.ts b/packages/renderer/src/create-audio.tsindex b4f951d987..58e2b3b0c5 100644--- a/packages/renderer/src/create-audio.ts+++ b/packages/renderer/src/create-audio.ts@@ -31,6 +31,7 @@ export const createAudio = async ({audioBitrate,audioCodec,cancelSignal,+ forSeamlessAacConcatentation,}: {assets: TRenderAsset[][];onDownload: RenderMediaOnDownload | undefined;@@ -45,6 +46,7 @@ export const createAudio = async ({audioBitrate: string | null;audioCodec: AudioCodec;cancelSignal: CancelSignal | undefined;+ forSeamlessAacConcatentation: boolean;}): Promise<string> => {const fileUrlAssets = await convertAssetsToFileUrls({assets,@@ -84,6 +86,7 @@ export const createAudio = async ({logLevel,binariesDirectory,cancelSignal,+ forSeamlessAacConcatentation,});preprocessProgress[index] = 1;updateProgress();diff --git a/packages/renderer/src/preprocess-audio-track.ts b/packages/renderer/src/preprocess-audio-track.tsindex 64c5689c27..9a75fb3be3 100644--- a/packages/renderer/src/preprocess-audio-track.ts+++ b/packages/renderer/src/preprocess-audio-track.ts@@ -22,6 +22,7 @@ type Options = {logLevel: LogLevel;binariesDirectory: string | null;cancelSignal: CancelSignal | undefined;+ forSeamlessAacConcatentation: boolean;};export type PreprocessedAudioTrack = {@@ -39,6 +40,7 @@ const preprocessAudioTrackUnlimited = async ({logLevel,binariesDirectory,cancelSignal,+ forSeamlessAacConcatentation,}: Options): Promise<PreprocessedAudioTrack | null> => {const {channels, duration} = await getAudioChannelsAndDuration({downloadMap,@@ -55,6 +57,7 @@ const preprocessAudioTrackUnlimited = async ({fps,channels,assetDuration: duration,+ forSeamlessAacConcatentation,});if (filter === null) {diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex 8b80c4b0af..d44451852b 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -125,6 +125,7 @@ export type InternalRenderMediaOptions = {finishRenderProgress: () => void;binariesDirectory: string | null;separateAudioTo: string | null;+ forSeamlessAacConcatentation: boolean;} & MoreRenderMediaOptions;type Prettify<T> = {@@ -181,6 +182,7 @@ export type RenderMediaOptions = Prettify<{repro?: boolean;binariesDirectory?: string | null;separateAudioTo?: string | null;+ forSeamlessAacConcatentation?: boolean;}> &Partial<MoreRenderMediaOptions>;@@ -241,6 +243,7 @@ const internalRenderMediaRaw = ({finishRenderProgress,binariesDirectory,separateAudioTo,+ forSeamlessAacConcatentation,}: InternalRenderMediaOptions): Promise<RenderMediaResult> => {if (repro) {enableRepro({@@ -693,6 +696,7 @@ const internalRenderMediaRaw = ({colorSpace,binariesDirectory,separateAudioTo,+ forSeamlessAacConcatentation,}),stitchStart,]);@@ -842,6 +846,7 @@ export const renderMedia = ({repro,binariesDirectory,separateAudioTo,+ forSeamlessAacConcatentation,}: RenderMediaOptions): Promise<RenderMediaResult> => {if (quality !== undefined) {console.warn(@@ -909,5 +914,6 @@ export const renderMedia = ({finishRenderProgress: () => undefined,binariesDirectory: binariesDirectory ?? null,separateAudioTo: separateAudioTo ?? null,+ forSeamlessAacConcatentation: forSeamlessAacConcatentation ?? false,});};diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 860fc1bce1..40c8ebcded 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -68,6 +68,7 @@ type InternalStitchFramesToVideoOptions = {colorSpace: ColorSpace;binariesDirectory: string | null;separateAudioTo: string | null;+ forSeamlessAacConcatentation: boolean;};export type StitchFramesToVideoOptions = {@@ -98,6 +99,7 @@ export type StitchFramesToVideoOptions = {colorSpace?: ColorSpace;binariesDirectory?: string | null;separateAudioTo?: string | null;+ forSeamlessAacConcatentation?: boolean;};type ReturnType = Promise<Buffer | null>;@@ -134,6 +136,7 @@ const innerStitchFramesToVideo = async (colorSpace,binariesDirectory,separateAudioTo,+ forSeamlessAacConcatentation,}: InternalStitchFramesToVideoOptions,remotionRoot: string,): Promise<ReturnType> => {@@ -265,6 +268,7 @@ const innerStitchFramesToVideo = async (audioBitrate,audioCodec: resolvedAudioCodec,cancelSignal: cancelSignal ?? undefined,+ forSeamlessAacConcatentation,}): null;@@ -495,6 +499,7 @@ export const stitchFramesToVideo = ({colorSpace,binariesDirectory,separateAudioTo,+ forSeamlessAacConcatentation,}: StitchFramesToVideoOptions): Promise<Buffer | null> => {return internalStitchFramesToVideo({assetsInfo,@@ -527,5 +532,6 @@ export const stitchFramesToVideo = ({colorSpace: colorSpace ?? 'default',binariesDirectory: binariesDirectory ?? null,separateAudioTo: separateAudioTo ?? null,+ forSeamlessAacConcatentation: forSeamlessAacConcatentation ?? false,});};diff --git a/packages/renderer/src/test/ffmpeg-filters.test.ts b/packages/renderer/src/test/ffmpeg-filters.test.tsindex af5f779a21..8e5808380b 100644--- a/packages/renderer/src/test/ffmpeg-filters.test.ts+++ b/packages/renderer/src/test/ffmpeg-filters.test.ts@@ -29,6 +29,7 @@ test('Should create a basic filter correctly', () => {durationInFrames: 100,channels: 1,assetDuration: 10,+ forSeamlessAacConcatentation: true,}),).toEqual({filter:@@ -45,6 +46,7 @@ test('Trim the end', () => {durationInFrames: 100,channels: 1,assetDuration: 10,+ forSeamlessAacConcatentation: true,}),).toEqual({filter:@@ -65,6 +67,7 @@ test('Should handle trim correctly', () => {durationInFrames: 100,channels: 1,assetDuration: 10,+ forSeamlessAacConcatentation: true,}),).toEqual({filter:@@ -85,6 +88,7 @@ test('Should add padding if audio is too short', () => {durationInFrames: 100,channels: 1,assetDuration: 1,+ forSeamlessAacConcatentation: true,}),).toEqual({filter:@@ -107,6 +111,7 @@ test('Should handle delay correctly', () => {durationInFrames: 100,channels: 1,assetDuration: 1,+ forSeamlessAacConcatentation: true,}),).toEqual({filter:@@ -128,6 +133,7 @@ test('Should offset multiple channels', () => {durationInFrames: 100,channels: 3,assetDuration: 1,+ forSeamlessAacConcatentation: true,}),).toEqual({filter:@@ -159,6 +165,7 @@ test('Should calculate pad correctly with a lot of playbackRate', () => {durationInFrames: 2000,channels: 1,assetDuration: 33.333333,+ forSeamlessAacConcatentation: true,}),).toEqual({filter: