Skip to content

🎥 Make videos programmatically with React

cool

Jonny Burgerf27ee4da8944
diff --git a/packages/renderer/src/combine-audio.ts b/packages/renderer/src/combine-audio.ts
index 2ab7ae9290..215ca103bc 100644
--- a/packages/renderer/src/combine-audio.ts
+++ b/packages/renderer/src/combine-audio.ts
@@ -31,6 +31,7 @@ const encodeAudio = async ({
fps,
binariesDirectory,
cancelSignal,
+ onProgress,
}: {
files: string[];
resolvedAudioCodec: AudioCodec;
@@ -43,6 +44,7 @@ const encodeAudio = async ({
fps: number;
binariesDirectory: string | null;
cancelSignal: CancelSignal | undefined;
+ onProgress: (frames: number) => void;
}) => {
const fileList = files.map((p) => `file '${p}'`).join('\n');
const fileListTxt = join(filelistDir, 'audio-files.txt');
@@ -89,6 +91,7 @@ const encodeAudio = async ({
if (parsed === undefined) {
Log.verbose({indent, logLevel}, utf8);
} else {
+ onProgress(parsed);
Log.verbose({indent, logLevel}, `Encoded ${parsed} audio frames`);
}
});
@@ -115,6 +118,7 @@ const combineAudioSeamlessly = async ({
fps,
binariesDirectory,
cancelSignal,
+ onProgress,
}: {
files: string[];
filelistDir: string;
@@ -126,6 +130,7 @@ const combineAudioSeamlessly = async ({
binariesDirectory: string | null;
cancelSignal: CancelSignal | undefined;
indent: boolean;
+ onProgress: (frames: number) => void;
}) => {
const startConcatenating = Date.now();
const fileList = files
@@ -201,6 +206,7 @@ const combineAudioSeamlessly = async ({
if (parsed === undefined) {
Log.verbose({indent, logLevel}, utf8);
} else {
+ onProgress(parsed);
Log.verbose({indent, logLevel}, `Encoded ${parsed} audio frames`);
}
});
@@ -231,6 +237,7 @@ export const createCombinedAudio = ({
binariesDirectory,
fps,
cancelSignal,
+ onProgress,
}: {
seamless: boolean;
filelistDir: string;
@@ -245,6 +252,7 @@ export const createCombinedAudio = ({
binariesDirectory: string | null;
fps: number;
cancelSignal: CancelSignal | undefined;
+ onProgress: (frames: number) => void;
}): Promise<string> => {
if (seamless) {
return combineAudioSeamlessly({
@@ -258,6 +266,7 @@ export const createCombinedAudio = ({
binariesDirectory,
fps,
cancelSignal,
+ onProgress,
});
}
@@ -273,5 +282,6 @@ export const createCombinedAudio = ({
binariesDirectory,
fps,
cancelSignal,
+ onProgress,
});
};
diff --git a/packages/renderer/src/combine-videos.ts b/packages/renderer/src/combine-videos.ts
index e544726f1f..6d6c5fd504 100644
--- a/packages/renderer/src/combine-videos.ts
+++ b/packages/renderer/src/combine-videos.ts
@@ -73,6 +73,20 @@ export const combineVideos = async ({
const audioFiles = files.filter((f) => f.endsWith('audio'));
const videoFiles = files.filter((f) => f.endsWith('video'));
+ let concatenatedAudio = 0;
+ let concatenatedVideo = 0;
+ let muxing = 0;
+
+ const updateProgress = () => {
+ const totalFrames =
+ (shouldCreateAudio ? numberOfFrames : 0) +
+ (shouldCreateVideo ? numberOfFrames : 0) +
+ numberOfFrames;
+ const actualProgress = concatenatedAudio + concatenatedVideo + muxing;
+
+ onProgress((actualProgress / totalFrames) * numberOfFrames);
+ };
+
await Promise.all(
[
shouldCreateAudio
@@ -90,6 +104,10 @@ export const combineVideos = async ({
binariesDirectory,
fps,
cancelSignal,
+ onProgress: (frames) => {
+ concatenatedAudio = frames;
+ updateProgress();
+ },
})
: null,
@@ -101,12 +119,15 @@ export const combineVideos = async ({
indent,
logLevel,
numberOfGifLoops,
- onProgress,
output: shouldCreateAudio ? videoOutput : output,
files: videoFiles,
addRemotionMetadata: !shouldCreateAudio,
binariesDirectory,
cancelSignal,
+ onProgress: (frames) => {
+ concatenatedVideo = frames;
+ updateProgress();
+ },
})
: null,
].filter(truthy),
@@ -122,7 +143,10 @@ export const combineVideos = async ({
audioOutput,
indent,
logLevel,
- onProgress,
+ onProgress: (frames) => {
+ muxing = frames;
+ updateProgress();
+ },
output,
videoOutput,
binariesDirectory,