Skip to content

🎥 Make videos programmatically with React

separate seamless techniques

Jonny Burgerfd5496f5527b
diff --git a/packages/docs/docs/lambda/rendermediaonlambda.md b/packages/docs/docs/lambda/rendermediaonlambda.md
index d74b961311..9e5713f02a 100644
--- a/packages/docs/docs/lambda/rendermediaonlambda.md
+++ b/packages/docs/docs/lambda/rendermediaonlambda.md
@@ -354,7 +354,7 @@ If the `logLevel` is set to `verbose`, the Lambda function will not clean up art
<Options id="delete-after"/>
-### `preferLossless?`<AvailableFrom v="4.0.110"/>
+### `preferLossless?`<AvailableFrom v="4.0.123"/>
<Options id="prefer-lossless" />
diff --git a/packages/lambda/src/functions/helpers/can-concat-seamlessly.ts b/packages/lambda/src/functions/helpers/can-concat-seamlessly.ts
index 9c69d4fee3..4307d417e4 100644
--- a/packages/lambda/src/functions/helpers/can-concat-seamlessly.ts
+++ b/packages/lambda/src/functions/helpers/can-concat-seamlessly.ts
@@ -1,8 +1,11 @@
-import type {AudioCodec, Codec} from '@remotion/renderer';
+import type {AudioCodec} from '@remotion/renderer';
-export const canConcatSeamlessly = (
- audioCodec: AudioCodec | null,
- codec: Codec,
-) => {
- return audioCodec === 'aac' && codec === 'h264';
+// There is seamless concatenation for audio and video.
+// Maybe we should separate this.
+export const canConcatAudioSeamlessly = (audioCodec: AudioCodec | null) => {
+ return audioCodec === 'aac';
+};
+
+export const canConcatVideoSeamlessly = (codec: string) => {
+ return codec === 'h264';
};
diff --git a/packages/lambda/src/functions/helpers/concat-videos.ts b/packages/lambda/src/functions/helpers/concat-videos.ts
index 2b0cba219e..42996cd295 100644
--- a/packages/lambda/src/functions/helpers/concat-videos.ts
+++ b/packages/lambda/src/functions/helpers/concat-videos.ts
@@ -11,7 +11,10 @@ import {
rendersPrefix,
} from '../../shared/constants';
import type {LambdaCodec} from '../../shared/validate-lambda-codec';
-import {canConcatSeamlessly} from './can-concat-seamlessly';
+import {
+ canConcatAudioSeamlessly,
+ canConcatVideoSeamlessly,
+} from './can-concat-seamlessly';
import {inspectErrors} from './inspect-errors';
import {lambdaLs, lambdaReadFile} from './io';
import {timer} from './timer';
@@ -218,7 +221,8 @@ export const concatVideosS3 = async ({
const chunkDurationInSeconds = framesPerLambda / fps;
- const seamless = canConcatSeamlessly(audioCodec, codec);
+ const seamlessAudio = canConcatAudioSeamlessly(audioCodec);
+ const seamlessVideo = canConcatVideoSeamlessly(codec);
await RenderInternals.combineVideos({
files,
@@ -236,7 +240,8 @@ export const concatVideosS3 = async ({
chunkDurationInSeconds,
binariesDirectory,
cancelSignal,
- seamless,
+ seamlessAudio,
+ seamlessVideo,
});
combine.end();
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index a814d0acf1..70dfb5ed33 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -20,7 +20,10 @@ import type {
ChunkTimingData,
ObjectChunkTimingData,
} from './chunk-optimization/types';
-import {canConcatSeamlessly} from './helpers/can-concat-seamlessly';
+import {
+ canConcatAudioSeamlessly,
+ canConcatVideoSeamlessly,
+} from './helpers/can-concat-seamlessly';
import {
forgetBrowserEventLoop,
getBrowserInstance,
@@ -109,16 +112,26 @@ const renderHandler = async (
preferLossless: params.preferLossless,
});
- const seamless = canConcatSeamlessly(defaultAudioCodec, params.codec);
+ const seamlessAudio = canConcatAudioSeamlessly(defaultAudioCodec);
+ const seamlessVideo = canConcatVideoSeamlessly(params.codec);
+
RenderInternals.Log.verbose(
{indent: false, logLevel: params.logLevel},
- `Preparing for rendering a ${seamless ? 'seamless' : 'normal'} chunk`,
+ `Preparing for rendering a chunk. Audio = ${
+ seamlessAudio ? 'seamless' : 'normal'
+ }, Video = ${seamlessVideo ? 'seamless' : 'normal'}`,
params.logLevel,
);
const chunkCodec: Codec =
- params.codec === 'gif' ? 'h264-mkv' : seamless ? 'h264-ts' : params.codec;
- const audioCodec: AudioCodec | null = seamless ? defaultAudioCodec : 'pcm-16';
+ params.codec === 'gif'
+ ? 'h264-mkv'
+ : seamlessVideo
+ ? 'h264-ts'
+ : params.codec;
+ const audioCodec: AudioCodec | null = seamlessAudio
+ ? defaultAudioCodec
+ : 'pcm-16';
const videoExtension = RenderInternals.getFileExtensionFromCodec(
chunkCodec,
@@ -239,7 +252,7 @@ const renderHandler = async (
finishRenderProgress: () => undefined,
binariesDirectory: null,
separateAudioTo: audioOutputLocation,
- forSeamlessAacConcatenation: seamless,
+ forSeamlessAacConcatenation: seamlessAudio,
})
.then(({slowestFrames}) => {
console.log(`Slowest frames:`);
diff --git a/packages/renderer/src/combine-videos.ts b/packages/renderer/src/combine-videos.ts
index 40287d8d94..a250001054 100644
--- a/packages/renderer/src/combine-videos.ts
+++ b/packages/renderer/src/combine-videos.ts
@@ -35,7 +35,8 @@ type Options = {
chunkDurationInSeconds: number;
binariesDirectory: string | null;
cancelSignal: CancelSignal | undefined;
- seamless: boolean;
+ seamlessAudio: boolean;
+ seamlessVideo: boolean;
};
export const combineVideos = async ({
@@ -54,7 +55,8 @@ export const combineVideos = async ({
chunkDurationInSeconds,
binariesDirectory,
cancelSignal,
- seamless,
+ seamlessAudio,
+ seamlessVideo,
}: Options) => {
const resolvedAudioCodec = resolveAudioCodec({
setting: audioCodecSetting,
@@ -97,7 +99,9 @@ export const combineVideos = async ({
Log.verbose(
{indent, logLevel},
- `Combining chunks ${seamless ? 'seamlessly' : 'normally'}`,
+ `Combining chunks, audio = ${
+ seamlessAudio ? 'seamlessly' : 'normally'
+ }, video = ${seamlessVideo ? 'seamlessly' : 'normally'}`,
);
await Promise.all(
[
@@ -110,7 +114,7 @@ export const combineVideos = async ({
logLevel,
output: shouldCreateVideo ? (audioOutput as string) : output,
resolvedAudioCodec,
- seamless,
+ seamless: seamlessAudio,
chunkDurationInSeconds,
addRemotionMetadata: !shouldCreateVideo,
binariesDirectory,
@@ -123,7 +127,7 @@ export const combineVideos = async ({
})
: null,
- shouldCreateVideo && !seamless
+ shouldCreateVideo && !seamlessVideo
? createCombinedVideo({
codec,
filelistDir,
@@ -140,7 +144,6 @@ export const combineVideos = async ({
concatenatedVideo = frames;
updateProgress();
},
- seamless,
})
: null,
].filter(truthy),
@@ -161,7 +164,7 @@ export const combineVideos = async ({
updateProgress();
},
output,
- videoOutput: seamless
+ videoOutput: seamlessVideo
? combineVideoStreamsSeamlessly({files: videoFiles})
: videoOutput,
binariesDirectory,
diff --git a/packages/renderer/src/create-combined-video.ts b/packages/renderer/src/create-combined-video.ts
index ac48d128c1..012eebf6fc 100644
--- a/packages/renderer/src/create-combined-video.ts
+++ b/packages/renderer/src/create-combined-video.ts
@@ -1,6 +1,5 @@
import type {Codec} from './codec';
import {combineVideoStreams} from './combine-video-streams';
-import {combineVideoStreamsSeamlessly} from './combine-video-streams-seamlessly';
import type {LogLevel} from './log-level';
import type {CancelSignal} from './make-cancel-signal';
@@ -17,7 +16,6 @@ export const createCombinedVideo = async ({
numberOfGifLoops,
onProgress,
output,
- seamless,
}: {
fps: number;
codec: Codec;
@@ -31,14 +29,7 @@ export const createCombinedVideo = async ({
addRemotionMetadata: boolean;
binariesDirectory: string | null;
cancelSignal: CancelSignal | undefined;
- seamless: boolean;
}) => {
- if (seamless) {
- return combineVideoStreamsSeamlessly({
- files,
- });
- }
-
await combineVideoStreams({
addRemotionMetadata,
binariesDirectory,