1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-27 17:00:52 +01:00

Added upscayl on folder

This commit is contained in:
Feenix 2022-12-04 06:29:16 +05:30
parent 6534037dbb
commit 3c7c0d9a4f
5 changed files with 92 additions and 69 deletions

2
.gitignore vendored
View File

@ -41,3 +41,5 @@ build-dir/
#vscode
.vscode/
main/*

View File

@ -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;

View File

@ -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,6 +413,31 @@ ipcMain.on(commands.UPSCAYL_VIDEO, async (event, payload) => {
}
);
let failed = false;
ffmpegProcess?.stderr.on("data", (data: string) => {
console.log("🚀 => file: index.ts:420 => data", data.toString());
data = data.toString();
mainWindow.webContents.send(
commands.FFMPEG_VIDEO_PROGRESS,
data.toString()
);
});
ffmpegProcess?.on("error", (data: string) => {
mainWindow.webContents.send(
commands.FFMPEG_VIDEO_PROGRESS,
data.toString()
);
failed = true;
return;
});
// Send done comamnd when
ffmpegProcess?.on("close", (code: number) => {
if (failed !== true) {
console.log("Frame extraction successful!");
mainWindow.webContents.send(commands.FFMPEG_VIDEO_DONE, outputDir);
// UPSCALE
let upscayl: ChildProcessWithoutNullStreams | null = null;
upscayl = spawn(
@ -416,7 +446,7 @@ ipcMain.on(commands.UPSCAYL_VIDEO, async (event, payload) => {
"-i",
frameExtractionPath,
"-o",
frameExtractionPath + "_upscaled",
frameUpscalePath,
"-s",
4,
"-m",
@ -430,7 +460,6 @@ ipcMain.on(commands.UPSCAYL_VIDEO, async (event, payload) => {
}
);
let failed = false;
upscayl?.stderr.on("data", (data) => {
console.log(
"🚀 => upscayl.stderr.on => stderr.toString()",
@ -438,28 +467,10 @@ ipcMain.on(commands.UPSCAYL_VIDEO, async (event, payload) => {
);
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) => {
mainWindow.webContents.send(
commands.UPSCAYL_VIDEO_PROGRESS,
data.toString()
);
failed = true;
return;
});
// Send done comamnd when
upscayl?.on("close", (code) => {
if (failed !== true) {
console.log("Done upscaling");
mainWindow.webContents.send(commands.UPSCAYL_VIDEO_DONE, outputDir);
}
});
});

View File

@ -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;

View File

@ -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,13 +319,29 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL_VIDEO, (event, payload) => __aw
cwd: undefined,
detached: false,
});
let failed = false;
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.FFMPEG_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
ffmpegProcess === null || ffmpegProcess === void 0 ? void 0 : ffmpegProcess.on("close", (code) => {
if (failed !== true) {
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",
frameExtractionPath + "_upscaled",
frameUpscalePath,
"-s",
4,
"-m",
@ -332,25 +352,11 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL_VIDEO, (event, payload) => __aw
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());
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());
failed = true;
return;
});
// Send done comamnd when
upscayl === null || upscayl === void 0 ? void 0 : upscayl.on("close", (code) => {
if (failed !== true) {
console.log("Done upscaling");
mainWindow.webContents.send(commands_1.default.UPSCAYL_VIDEO_DONE, outputDir);
}
});
}));