mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-12 01:40:53 +01:00
Added upscayl video functions
This commit is contained in:
parent
4caa5bc7ce
commit
0ce6046350
@ -229,11 +229,8 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
||||
let outputDir = payload.outputPath;
|
||||
|
||||
// COPY IMAGE TO TMP FOLDER
|
||||
const platform = getPlatform();
|
||||
const fullfileName =
|
||||
platform === "win"
|
||||
? payload.imagePath.split("\\").slice(-1)[0]
|
||||
: payload.imagePath.split("/").slice(-1)[0];
|
||||
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "");
|
||||
|
||||
console.log(fullfileName);
|
||||
const fileName = parse(fullfileName).name;
|
||||
const fileExt = parse(fullfileName).ext;
|
||||
@ -329,107 +326,28 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
||||
|
||||
//------------------------Video Upscayl-----------------------------//
|
||||
ipcMain.on(commands.UPSCAYL_VIDEO, async (event, payload) => {
|
||||
// Extract the model
|
||||
const model = payload.model;
|
||||
const scale = payload.scaleFactor;
|
||||
|
||||
// Extract the Video Directory
|
||||
let videoFileName = payload.videoPath.replace(/^.*[\\\/]/, "");
|
||||
const justFileName = parse(videoFileName).name;
|
||||
|
||||
let inputDir = payload.videoPath.match(/(.*)[\/\\]/)[1] || "";
|
||||
let outputDir = payload.outputPath;
|
||||
console.log("🚀 => file: index.ts => line 337 => inputDir", inputDir);
|
||||
|
||||
// COPY IMAGE TO TMP FOLDER
|
||||
const platform = getPlatform();
|
||||
const fullfileName =
|
||||
platform === "win"
|
||||
? payload.videoPath.split("\\").slice(-1)[0]
|
||||
: payload.videoPath.split("/").slice(-1)[0];
|
||||
console.log(fullfileName);
|
||||
const fileName = parse(fullfileName).name;
|
||||
const fileExt = parse(fullfileName).ext;
|
||||
const outFile = model.includes("realesrgan")
|
||||
? outputDir + "/" + fileName + "_upscayl_" + scale + "x_" + model + fileExt
|
||||
: outputDir +
|
||||
"/" +
|
||||
fileName +
|
||||
"_upscayl_sharpened_" +
|
||||
scale +
|
||||
"x_" +
|
||||
model +
|
||||
fileExt;
|
||||
// UPSCALE
|
||||
if (fs.existsSync(outFile)) {
|
||||
// If already upscayled, just output that file
|
||||
mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile);
|
||||
} else {
|
||||
let upscayl: ChildProcessWithoutNullStreams | null = null;
|
||||
switch (model) {
|
||||
case "realesrgan-x4plus":
|
||||
case "realesrgan-x4plus-anime":
|
||||
upscayl = spawn(
|
||||
execPath("realesrgan"),
|
||||
[
|
||||
"-i",
|
||||
inputDir + "/" + fullfileName,
|
||||
"-o",
|
||||
outFile,
|
||||
"-s",
|
||||
scale === 2 ? 4 : scale,
|
||||
"-m",
|
||||
modelsPath,
|
||||
"-n",
|
||||
model,
|
||||
],
|
||||
{
|
||||
cwd: undefined,
|
||||
detached: false,
|
||||
}
|
||||
);
|
||||
break;
|
||||
case "models-DF2K":
|
||||
upscayl = spawn(
|
||||
execPath("realsr"),
|
||||
[
|
||||
"-i",
|
||||
inputDir + "/" + fullfileName,
|
||||
"-o",
|
||||
outFile,
|
||||
"-s",
|
||||
scale,
|
||||
"-x",
|
||||
"-m",
|
||||
modelsPath + "/" + model,
|
||||
],
|
||||
{
|
||||
cwd: undefined,
|
||||
detached: false,
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
// Set the output directory
|
||||
let outputDir = payload.outputPath + "_frames";
|
||||
console.log("🚀 => file: index.ts => line 340 => outputDir", outputDir);
|
||||
|
||||
let failed = false;
|
||||
upscayl?.stderr.on("data", (data) => {
|
||||
console.log(
|
||||
"🚀 => upscayl.stderr.on => stderr.toString()",
|
||||
data.toString()
|
||||
);
|
||||
data = data.toString();
|
||||
mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString());
|
||||
if (data.includes("invalid gpu") || data.includes("failed")) {
|
||||
failed = true;
|
||||
}
|
||||
});
|
||||
let frameExtractionPath = join(inputDir, justFileName + "_frames");
|
||||
console.log(
|
||||
"🚀 => file: index.ts => line 342 => frameExtractionPath",
|
||||
frameExtractionPath
|
||||
);
|
||||
|
||||
upscayl?.on("error", (data) => {
|
||||
mainWindow.webContents.send(commands.UPSCAYL_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_DONE, outFile);
|
||||
}
|
||||
});
|
||||
if (!fs.existsSync(frameExtractionPath)) {
|
||||
fs.mkdirSync(frameExtractionPath, { recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
|
102
main/index.js
102
main/index.js
@ -202,10 +202,7 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter(
|
||||
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || "";
|
||||
let outputDir = payload.outputPath;
|
||||
// COPY IMAGE TO TMP FOLDER
|
||||
const platform = (0, getPlatform_1.default)();
|
||||
const fullfileName = platform === "win"
|
||||
? payload.imagePath.split("\\").slice(-1)[0]
|
||||
: payload.imagePath.split("/").slice(-1)[0];
|
||||
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "");
|
||||
console.log(fullfileName);
|
||||
const fileName = (0, path_1.parse)(fullfileName).name;
|
||||
const fileExt = (0, path_1.parse)(fullfileName).ext;
|
||||
@ -287,93 +284,22 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter(
|
||||
}));
|
||||
//------------------------Video Upscayl-----------------------------//
|
||||
electron_1.ipcMain.on(commands_1.default.UPSCAYL_VIDEO, (event, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
// Extract the model
|
||||
const model = payload.model;
|
||||
const scale = payload.scaleFactor;
|
||||
// Extract the Video Directory
|
||||
let videoFileName = payload.videoPath.replace(/^.*[\\\/]/, "");
|
||||
const justFileName = (0, path_1.parse)(videoFileName).name;
|
||||
let inputDir = payload.videoPath.match(/(.*)[\/\\]/)[1] || "";
|
||||
let outputDir = payload.outputPath;
|
||||
// COPY IMAGE TO TMP FOLDER
|
||||
const platform = (0, getPlatform_1.default)();
|
||||
const fullfileName = platform === "win"
|
||||
? payload.videoPath.split("\\").slice(-1)[0]
|
||||
: payload.videoPath.split("/").slice(-1)[0];
|
||||
console.log(fullfileName);
|
||||
const fileName = (0, path_1.parse)(fullfileName).name;
|
||||
const fileExt = (0, path_1.parse)(fullfileName).ext;
|
||||
const outFile = model.includes("realesrgan")
|
||||
? outputDir + "/" + fileName + "_upscayl_" + scale + "x_" + model + fileExt
|
||||
: outputDir +
|
||||
"/" +
|
||||
fileName +
|
||||
"_upscayl_sharpened_" +
|
||||
scale +
|
||||
"x_" +
|
||||
model +
|
||||
fileExt;
|
||||
// UPSCALE
|
||||
if (fs_1.default.existsSync(outFile)) {
|
||||
// If already upscayled, just output that file
|
||||
mainWindow.webContents.send(commands_1.default.UPSCAYL_DONE, outFile);
|
||||
}
|
||||
else {
|
||||
let upscayl = null;
|
||||
switch (model) {
|
||||
case "realesrgan-x4plus":
|
||||
case "realesrgan-x4plus-anime":
|
||||
upscayl = (0, child_process_1.spawn)((0, binaries_1.execPath)("realesrgan"), [
|
||||
"-i",
|
||||
inputDir + "/" + fullfileName,
|
||||
"-o",
|
||||
outFile,
|
||||
"-s",
|
||||
scale === 2 ? 4 : scale,
|
||||
"-m",
|
||||
binaries_1.modelsPath,
|
||||
"-n",
|
||||
model,
|
||||
], {
|
||||
cwd: undefined,
|
||||
detached: false,
|
||||
});
|
||||
break;
|
||||
case "models-DF2K":
|
||||
upscayl = (0, child_process_1.spawn)((0, binaries_1.execPath)("realsr"), [
|
||||
"-i",
|
||||
inputDir + "/" + fullfileName,
|
||||
"-o",
|
||||
outFile,
|
||||
"-s",
|
||||
scale,
|
||||
"-x",
|
||||
"-m",
|
||||
binaries_1.modelsPath + "/" + model,
|
||||
], {
|
||||
cwd: undefined,
|
||||
detached: false,
|
||||
});
|
||||
break;
|
||||
}
|
||||
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_PROGRESS, data.toString());
|
||||
if (data.includes("invalid gpu") || data.includes("failed")) {
|
||||
failed = true;
|
||||
}
|
||||
});
|
||||
upscayl === null || upscayl === void 0 ? void 0 : upscayl.on("error", (data) => {
|
||||
mainWindow.webContents.send(commands_1.default.UPSCAYL_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_DONE, outFile);
|
||||
}
|
||||
});
|
||||
console.log("🚀 => file: index.ts => line 337 => inputDir", inputDir);
|
||||
// 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);
|
||||
if (!fs_1.default.existsSync(frameExtractionPath)) {
|
||||
fs_1.default.mkdirSync(frameExtractionPath, { recursive: true });
|
||||
}
|
||||
console.log(upscayl_ffmpeg_1.default.path());
|
||||
}));
|
||||
//------------------------Upscayl Folder-----------------------------//
|
||||
electron_1.ipcMain.on(commands_1.default.FOLDER_UPSCAYL, (event, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
|
@ -284,7 +284,7 @@ const Home = () => {
|
||||
} else {
|
||||
setUpscaledImagePath("");
|
||||
}
|
||||
if (imagePath !== "" || batchFolderPath !== "") {
|
||||
if (!isVideo && (imagePath !== "" || batchFolderPath !== "")) {
|
||||
setProgress("Hold on...");
|
||||
if (model === "models-DF2K") {
|
||||
setDoubleUpscayl(false);
|
||||
@ -312,15 +312,15 @@ const Home = () => {
|
||||
model,
|
||||
});
|
||||
}
|
||||
} else if (videoPath !== "") {
|
||||
} else if (isVideo && videoPath !== "") {
|
||||
await window.electron.send(commands.UPSCAYL_VIDEO, {
|
||||
scaleFactor,
|
||||
imagePath,
|
||||
videoPath,
|
||||
outputPath,
|
||||
model,
|
||||
});
|
||||
} else {
|
||||
alert("Please select an image to upscale");
|
||||
alert(`Please select ${isVideo ? "a video" : "an image"} to upscale`);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user