From 3c7c0d9a4f091243fb71714cd2679052446d571b Mon Sep 17 00:00:00 2001 From: Feenix <25067102+NayamAmarshe@users.noreply.github.com> Date: Sun, 4 Dec 2022 06:29:16 +0530 Subject: [PATCH] Added upscayl on folder --- .gitignore | 4 +- electron/commands.ts | 2 + electron/index.ts | 87 +++++++++++++++++++++++++------------------- main/commands.js | 2 + main/index.js | 66 ++++++++++++++++++--------------- 5 files changed, 92 insertions(+), 69 deletions(-) diff --git a/.gitignore b/.gitignore index 69cf607..8d88d9d 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,6 @@ repo/ build-dir/ #vscode -.vscode/ \ No newline at end of file +.vscode/ + +main/* \ No newline at end of file diff --git a/electron/commands.ts b/electron/commands.ts index 58be005..cc9dad4 100644 --- a/electron/commands.ts +++ b/electron/commands.ts @@ -15,6 +15,8 @@ const commands = { UPSCAYL_VIDEO: "Upscale the Video", UPSCAYL_VIDEO_DONE: "Video Upscaling Done", UPSCAYL_VIDEO_PROGRESS: "Send Video Upscale Progress from Main to Renderer", + FFMPEG_VIDEO_DONE: "Ran FFMpeg successfully", + FFMPEG_VIDEO_PROGRESS: "Running FFMpeg for frame extraction", }; export default commands; diff --git a/electron/index.ts b/electron/index.ts index ca2f2c9..7ec83b3 100644 --- a/electron/index.ts +++ b/electron/index.ts @@ -384,15 +384,20 @@ ipcMain.on(commands.UPSCAYL_VIDEO, async (event, payload) => { let outputDir = payload.outputPath + "_frames"; console.log("🚀 => file: index.ts => line 340 => outputDir", outputDir); - let frameExtractionPath = join(inputDir, justFileName + "_frames"); + let frameExtractionPath = join(inputDir, justFileName + "_f"); + let frameUpscalePath = join(inputDir, justFileName + "_u"); console.log( "🚀 => file: index.ts => line 342 => frameExtractionPath", - frameExtractionPath + frameExtractionPath, + frameUpscalePath ); if (!fs.existsSync(frameExtractionPath)) { fs.mkdirSync(frameExtractionPath, { recursive: true }); } + if (!fs.existsSync(frameUpscalePath)) { + fs.mkdirSync(frameUpscalePath, { recursive: true }); + } let ffmpegProcess: ChildProcessWithoutNullStreams | null = null; ffmpegProcess = spawn( @@ -408,47 +413,19 @@ ipcMain.on(commands.UPSCAYL_VIDEO, async (event, payload) => { } ); - // UPSCALE - let upscayl: ChildProcessWithoutNullStreams | null = null; - upscayl = spawn( - execPath("realesrgan"), - [ - "-i", - frameExtractionPath, - "-o", - frameExtractionPath + "_upscaled", - "-s", - 4, - "-m", - modelsPath, - "-n", - model, - ], - { - cwd: undefined, - detached: false, - } - ); - let failed = false; - upscayl?.stderr.on("data", (data) => { - console.log( - "🚀 => upscayl.stderr.on => stderr.toString()", - data.toString() - ); + ffmpegProcess?.stderr.on("data", (data: string) => { + console.log("🚀 => file: index.ts:420 => data", data.toString()); data = data.toString(); mainWindow.webContents.send( - commands.UPSCAYL_VIDEO_PROGRESS, + commands.FFMPEG_VIDEO_PROGRESS, data.toString() ); - if (data.includes("invalid gpu") || data.includes("failed")) { - failed = true; - } }); - upscayl?.on("error", (data) => { + ffmpegProcess?.on("error", (data: string) => { mainWindow.webContents.send( - commands.UPSCAYL_VIDEO_PROGRESS, + commands.FFMPEG_VIDEO_PROGRESS, data.toString() ); failed = true; @@ -456,10 +433,44 @@ ipcMain.on(commands.UPSCAYL_VIDEO, async (event, payload) => { }); // Send done comamnd when - upscayl?.on("close", (code) => { + ffmpegProcess?.on("close", (code: number) => { if (failed !== true) { - console.log("Done upscaling"); - mainWindow.webContents.send(commands.UPSCAYL_VIDEO_DONE, outputDir); + console.log("Frame extraction successful!"); + mainWindow.webContents.send(commands.FFMPEG_VIDEO_DONE, outputDir); + + // UPSCALE + let upscayl: ChildProcessWithoutNullStreams | null = null; + upscayl = spawn( + execPath("realesrgan"), + [ + "-i", + frameExtractionPath, + "-o", + frameUpscalePath, + "-s", + 4, + "-m", + modelsPath, + "-n", + model, + ], + { + cwd: undefined, + detached: false, + } + ); + + upscayl?.stderr.on("data", (data) => { + console.log( + "🚀 => upscayl.stderr.on => stderr.toString()", + data.toString() + ); + data = data.toString(); + mainWindow.webContents.send( + commands.FFMPEG_VIDEO_PROGRESS, + data.toString() + ); + }); } }); }); diff --git a/main/commands.js b/main/commands.js index 11437a0..bc6485b 100644 --- a/main/commands.js +++ b/main/commands.js @@ -16,5 +16,7 @@ const commands = { UPSCAYL_VIDEO: "Upscale the Video", UPSCAYL_VIDEO_DONE: "Video Upscaling Done", UPSCAYL_VIDEO_PROGRESS: "Send Video Upscale Progress from Main to Renderer", + FFMPEG_VIDEO_DONE: "Ran FFMpeg successfully", + FFMPEG_VIDEO_PROGRESS: "Running FFMpeg for frame extraction", }; exports.default = commands; diff --git a/main/index.js b/main/index.js index d635168..26f0e52 100644 --- a/main/index.js +++ b/main/index.js @@ -301,11 +301,15 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL_VIDEO, (event, payload) => __aw // Set the output directory let outputDir = payload.outputPath + "_frames"; console.log("🚀 => file: index.ts => line 340 => outputDir", outputDir); - let frameExtractionPath = (0, path_1.join)(inputDir, justFileName + "_frames"); - console.log("🚀 => file: index.ts => line 342 => frameExtractionPath", frameExtractionPath); + let frameExtractionPath = (0, path_1.join)(inputDir, justFileName + "_f"); + let frameUpscalePath = (0, path_1.join)(inputDir, justFileName + "_u"); + console.log("🚀 => file: index.ts => line 342 => frameExtractionPath", frameExtractionPath, frameUpscalePath); if (!fs_1.default.existsSync(frameExtractionPath)) { fs_1.default.mkdirSync(frameExtractionPath, { recursive: true }); } + if (!fs_1.default.existsSync(frameUpscalePath)) { + fs_1.default.mkdirSync(frameUpscalePath, { recursive: true }); + } let ffmpegProcess = null; ffmpegProcess = (0, child_process_1.spawn)(upscayl_ffmpeg_1.default.path, [ "-i", @@ -315,42 +319,44 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL_VIDEO, (event, payload) => __aw cwd: undefined, detached: false, }); - // UPSCALE - let upscayl = null; - upscayl = (0, child_process_1.spawn)((0, binaries_1.execPath)("realesrgan"), [ - "-i", - frameExtractionPath, - "-o", - frameExtractionPath + "_upscaled", - "-s", - 4, - "-m", - binaries_1.modelsPath, - "-n", - model, - ], { - cwd: undefined, - detached: false, - }); let failed = false; - upscayl === null || upscayl === void 0 ? void 0 : upscayl.stderr.on("data", (data) => { - console.log("🚀 => upscayl.stderr.on => stderr.toString()", data.toString()); + ffmpegProcess === null || ffmpegProcess === void 0 ? void 0 : ffmpegProcess.stderr.on("data", (data) => { + console.log("🚀 => file: index.ts:420 => data", data.toString()); data = data.toString(); - mainWindow.webContents.send(commands_1.default.UPSCAYL_VIDEO_PROGRESS, data.toString()); - if (data.includes("invalid gpu") || data.includes("failed")) { - failed = true; - } + mainWindow.webContents.send(commands_1.default.FFMPEG_VIDEO_PROGRESS, data.toString()); }); - upscayl === null || upscayl === void 0 ? void 0 : upscayl.on("error", (data) => { - mainWindow.webContents.send(commands_1.default.UPSCAYL_VIDEO_PROGRESS, data.toString()); + ffmpegProcess === null || ffmpegProcess === void 0 ? void 0 : ffmpegProcess.on("error", (data) => { + mainWindow.webContents.send(commands_1.default.FFMPEG_VIDEO_PROGRESS, data.toString()); failed = true; return; }); // Send done comamnd when - upscayl === null || upscayl === void 0 ? void 0 : upscayl.on("close", (code) => { + ffmpegProcess === null || ffmpegProcess === void 0 ? void 0 : ffmpegProcess.on("close", (code) => { if (failed !== true) { - console.log("Done upscaling"); - mainWindow.webContents.send(commands_1.default.UPSCAYL_VIDEO_DONE, outputDir); + console.log("Frame extraction successful!"); + mainWindow.webContents.send(commands_1.default.FFMPEG_VIDEO_DONE, outputDir); + // UPSCALE + let upscayl = null; + upscayl = (0, child_process_1.spawn)((0, binaries_1.execPath)("realesrgan"), [ + "-i", + frameExtractionPath, + "-o", + frameUpscalePath, + "-s", + 4, + "-m", + binaries_1.modelsPath, + "-n", + model, + ], { + cwd: undefined, + detached: false, + }); + upscayl === null || upscayl === void 0 ? void 0 : upscayl.stderr.on("data", (data) => { + console.log("🚀 => upscayl.stderr.on => stderr.toString()", data.toString()); + data = data.toString(); + mainWindow.webContents.send(commands_1.default.FFMPEG_VIDEO_PROGRESS, data.toString()); + }); } }); }));