Skip to content

🎥 Make videos programmatically with React

try to fix silent audio bug

Jonny Burger766019c53352
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 26c5d1d43e..9b6e20eced 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -173,7 +173,12 @@ const renderHandler = async (
webpackBundle: null,
});
stitchLabel.end();
- await RenderInternals.addSilentAudioIfNecessary(outputLocation);
+ console.info('Adding silent audio, chunk', params.chunk);
+ await RenderInternals.addSilentAudioIfNecessary(
+ outputLocation,
+ params.frameRange[1] - params.frameRange[0] + 1,
+ params.fps
+ );
const endStitching = Date.now();
const condensedTimingData: ChunkTimingData = {
diff --git a/packages/renderer/src/add-silent-audio-if-necessary.ts b/packages/renderer/src/add-silent-audio-if-necessary.ts
index e22e0d33e3..6dd1ade99b 100644
--- a/packages/renderer/src/add-silent-audio-if-necessary.ts
+++ b/packages/renderer/src/add-silent-audio-if-necessary.ts
@@ -3,7 +3,9 @@ import {renameSync, unlinkSync} from 'fs';
import {getAudioChannels} from './assets/get-audio-channels';
export const addSilentAudioIfNecessary = async (
- videoFile: string
+ videoFile: string,
+ durationInFrames: number,
+ fps: number
): Promise<void> => {
const audioChannels = await getAudioChannels(videoFile);
if (audioChannels > 0) {
@@ -28,7 +30,8 @@ export const addSilentAudioIfNecessary = async (
'-c:v',
'copy',
'-y',
- '-shortest',
+ '-t',
+ (durationInFrames / fps).toFixed(4),
'-f',
'matroska',
out,