How to use FFmpeg.wasm to add audio to a video in Nodejs. Like adding some background audio to a video in Nodejs? Can anyone here please help me with this? https://github.com/FFmpeg-wasm/FFmpeg.wasm
Reel3.mp4 is a video and wolf-howl-6310.mp3 is the audio that i want to merge. What i tried?
import { readFile, writeFile } from "fs/promises";
import { FFmpeg } from "@ffmpeg.wasm/main";
import path from "path";
const currentDirectory = process.cwd();
const inputFilePath = path.join(currentDirectory, "Reel3.mp4");
const outputFilePath = path.join(currentDirectory, "Reel3.mp4");
const ffmpeg = await FFmpeg.create({ core: "@ffmpeg.wasm/core-mt" });
try {
await ffmpeg.fs.writeFile("Reel3", await readFile(inputFilePath));
await ffmpeg.run("-i", "wolf-howl-6310", "wolf-howl-6310.mp3");
await writeFile(outputFilePath, ffmpeg.fs.readFile("Reel3.mp4"));
console.log("Conversion successful!");
} catch (error) {
console.error("Error:", error);
} finally {
process.exit(0);
}