Add the merged track to the original

This commit is contained in:
Mylloon 2023-07-30 02:29:02 +02:00
parent f29c50c14d
commit 45235e63ce
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -2,6 +2,7 @@ import { FileFilter, BrowserWindow, app, dialog, ipcMain } from "electron";
import path = require("path"); import path = require("path");
import ffmpegPath = require("ffmpeg-static"); import ffmpegPath = require("ffmpeg-static");
import child_process = require("child_process"); import child_process = require("child_process");
import { unlink } from "fs";
/** Create a new window */ /** Create a new window */
const createWindow = () => { const createWindow = () => {
@ -31,14 +32,24 @@ const getNewFilename = (ogFile: string, part: string) => {
/** Merge all audios track of a video into one */ /** Merge all audios track of a video into one */
const mergeAudio = (file: string) => { const mergeAudio = (file: string) => {
const tmp_file = getNewFilename(file, "TMP_");
const outFile = getNewFilename(file, "(merged audio) "); const outFile = getNewFilename(file, "(merged audio) ");
const child = child_process.exec(
`${ffmpegPath} -i "${file}" -filter_complex "[0:a]amerge=inputs=2[a]" -ac 1 -map 0:v -map "[a]" -c:v copy "${outFile}"` // Merge 2 audio
child_process.execSync(
`${ffmpegPath} -i "${file}" -filter_complex "[0:a]amerge=inputs=2[a]" -ac 1 -map 0:v -map "[a]" -c:v copy -y "${tmp_file}"`
); );
/* debug */ // Add merged audio as first position to original video
child.stderr.on("data", (err) => { child_process.execSync(
console.log("stderr", err.toString()); `${ffmpegPath} -i "${tmp_file}" -i "${file}" -map 0 -map 1:a -c:v copy -y "${outFile}"`
);
// Delete the temporary file
unlink(tmp_file, (err) => {
if (err) {
throw err;
}
}); });
return outFile; return outFile;