1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-23 23:21:05 +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

4
.gitignore vendored
View File

@ -40,4 +40,6 @@ repo/
build-dir/
#vscode
.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,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()
);
});
}
});
});

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,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());
});
}
});
}));