模型压平

This commit is contained in:
2025-09-11 18:06:03 +08:00
parent 0e8793f01d
commit 485c6067c8
41 changed files with 571 additions and 74 deletions

22
src/preload/config.ts Normal file
View File

@ -0,0 +1,22 @@
//获取项目根目录
function GetHomeDir() {
let HOME_DIR = process.cwd();
console.log("process.env.NODE_ENV", process.env.NODE_ENV);
if (process.env.NODE_ENV === "production") {
let arr = process.execPath.replaceAll("\\", "/").split("/");
arr.pop();
HOME_DIR = arr.join("/");
}
return HOME_DIR;
}
//获取项目根目录
function GetAsar() {
let HOME_DIR = process.cwd();
if (process.env.NODE_ENV === "production") {
let arr = process.execPath.replaceAll("\\", "/").split("/");
arr.pop();
HOME_DIR = arr.join("/");
}
return HOME_DIR;
}
export { GetHomeDir, GetAsar };

View File

@ -23,3 +23,4 @@ if (process.contextIsolated) {
// @ts-ignore (define in dts)
window.YJColorPicker = YJColorPicker
}

113
src/preload/recorder.ts Normal file
View File

@ -0,0 +1,113 @@
import path from "path";
import { GetHomeDir } from "./config";
const os = require("os");
const fs = require("fs");
let platform = os.platform();
const arch = os.arch();
const moment = require("moment");
const { spawn } = require("child_process");
const EventEmitter = require("events");
let ffmpegExePath = path.join(GetHomeDir(), "ffplay");
class MyEmitter extends EventEmitter { }
const myEmitter = new MyEmitter();
class Recorder {
constructor(option = {}) {
this.shell = undefined;
this.filename =
moment(parseInt(new Date().getTime())).format("YYYYMMDDHHmmss") + ".mp4";
this.exe = "ffmpeg.exe";
if (platform === "win32") {
this.exe = "ffmpeg.exe";
this.params = "-f gdigrab -r 30 -y -i desktop -pix_fmt yuv420p";
}
if (platform === "linux") {
switch (arch) {
case "x64":
this.exe = "ffmpeg_x86";
break;
case "arm":
this.exe = "ffmpeg_arm";
break;
}
this.params =
"-v verbose -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 -c:v libx264 -preset ultrafast -crf 18";
//-s 1920x1080
// ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 -c:v libx264 -preset ultrafast -crf 18 output.mp4
}
this.commands = path.join(GetHomeDir(), "/ffplay/" + this.exe);
}
get_path() {
return path.join(ffmpegExePath, this.filename);
}
start() {
this.exec(this.commands, this.params);
}
exec(commands, param) {
let arr = param.split(" ");
arr.push(this.get_path());
console.log("commands, arr", commands, arr);
this.shell = spawn(commands, arr, {
ffmpegExePath,
// stdio: "ignore",
// shell: true
})
.on("exit", (err) => {
console.log("exit", err);
myEmitter.emit("process-exit");
})
.on("data", function (data) {
// console.log(typeof data);
})
.on("data", function (data) { });
this.shell.unref();
}
end(cb) {
if (!this.shell.killed) {
console.log(this.shell);
this.shell.stdin.write("q");
myEmitter.once("process-exit", () => {
cb();
});
} else {
cb();
}
}
move(dst, cb) {
let readStream = fs.createReadStream(this.get_path());
let writeStream = fs.createWriteStream(dst);
readStream.pipe(writeStream);
readStream.on("end", () => {
fs.unlinkSync(this.get_path());
cb();
});
}
}
/*function start() {
config.recorder = new Recorder()
config.recorder.start()
}
function end(cb) {
config.recorder.end(() => {
cb()
})
}
function getRecorder() {
return config.recorder
}
function resetRecorder() {
config.recorder = null
}
exports.Recorder = {
start,
end,
getRecorder,
resetRecorder,
}*/
export { Recorder };