Skip to content

Commit

Permalink
超级录屏 mp4
Browse files Browse the repository at this point in the history
  • Loading branch information
xushengfeng committed Oct 7, 2024
1 parent add3d23 commit e4465be
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"hex-to-css-filter": "^5.4.0",
"hotkeys-js": "^3.13.7",
"minimist": "^1.2.8",
"mp4-muxer": "^5.1.3",
"node-screenshots": "^0.1.9",
"onnxruntime-node": "^1.18.0",
"opencv.js": "^1.2.1",
Expand Down
12 changes: 11 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion src/renderer/videoEditor/videoEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async function transform(_codec: string = codec) {
vp8: "vp8",
vp9: "vp09.00.10.08",
av1: "av01.0.04M.08",
avc: "avc1.42001E",
avc: "avc1.42001F",
};
// todo 回退
encoder.configure({
Expand Down Expand Up @@ -338,6 +338,9 @@ async function save() {
else if (exportEl.els.type.gv === "webm-av1") saveWebm("av1");
else if (exportEl.els.type.gv === "webm-vp9") saveWebm("vp9");
else if (exportEl.els.type.gv === "webm-vp8") saveWebm("vp8");
else if (exportEl.els.type.gv === "mp4-av1") saveMp4("av1");
else if (exportEl.els.type.gv === "mp4-vp9") saveMp4("vp9");
else if (exportEl.els.type.gv === "mp4-avc") saveMp4("avc");
}

function getSavePath(type: baseType) {
Expand Down Expand Up @@ -442,6 +445,32 @@ async function saveWebm(_codec: "vp8" | "vp9" | "av1") {
console.log("saved webm");
}

async function saveMp4(_codec: "avc" | "vp9" | "av1") {
const { Muxer, ArrayBufferTarget } =
require("mp4-muxer") as typeof import("mp4-muxer");
const muxer = new Muxer({
target: new ArrayBufferTarget(),
video: {
codec: _codec,
width: outputV.width,
height: outputV.height,
},
fastStart: false,
});

await transform(_codec);

for (const chunk of transformed) {
muxer.addVideoChunk(chunk);
}
muxer.finalize();
const { buffer } = muxer.target;
const exportPath = getSavePath("mp4");
// @ts-ignore
fs.writeFileSync(exportPath, Buffer.from(buffer));
console.log("saved mp4");
}

ipcRenderer.on("record", async (e, t, sourceId) => {
// return
let stream: MediaStream | undefined;
Expand Down

0 comments on commit e4465be

Please sign in to comment.