mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 15:18:22 +00:00
enhancement(lint): Fix lint errors for scripts/remove_bg.ts
Co-authored-by: NeonGamerBot-QK <saahilattud@gmail.com> Signed-off-by: zeon-neon[bot] <136533918+zeon-neon[bot]@users.noreply.github.com>
This commit is contained in:
parent
b643f7d755
commit
aa170d6741
1 changed files with 31 additions and 20 deletions
|
|
@ -5,18 +5,20 @@
|
|||
|
||||
import canvas from "canvas";
|
||||
import { execSync } from "child_process";
|
||||
const { createCanvas, loadImage } = canvas
|
||||
import fs, { existsSync, readdirSync } from "fs"
|
||||
const { createCanvas, loadImage } = canvas;
|
||||
import fs, { existsSync, readdirSync } from "fs";
|
||||
// rmrif frames and remake
|
||||
execSync(`rm -rf assets/dice/frames`, { stdio: 'inherit' })
|
||||
execSync(`mkdir assets/dice/frames`, { stdio: 'inherit' })
|
||||
if(!process.env.VIDEO_FILE) process.env.VIDEO_FILE=`assets/dice/green_screen_dice.mp4`
|
||||
if(!process.env.OUT_FILE) process.env.OUT_FILE=`assets/dice/no_green_screen_dice.mp4`
|
||||
execSync(`rm -rf assets/dice/frames`, { stdio: "inherit" });
|
||||
execSync(`mkdir assets/dice/frames`, { stdio: "inherit" });
|
||||
if (!process.env.VIDEO_FILE)
|
||||
process.env.VIDEO_FILE = `assets/dice/green_screen_dice.mp4`;
|
||||
if (!process.env.OUT_FILE)
|
||||
process.env.OUT_FILE = `assets/dice/no_green_screen_dice.mp4`;
|
||||
const removeGreenScreen = async (inputPath, outputPath) => {
|
||||
const image = await loadImage(inputPath);
|
||||
|
||||
const canvas = createCanvas(image.width, image.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
||||
ctx.drawImage(image, 0, 0, image.width, image.height);
|
||||
|
||||
|
|
@ -35,23 +37,32 @@ const removeGreenScreen = async (inputPath, outputPath) => {
|
|||
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
|
||||
const buffer = canvas.toBuffer('image/png');
|
||||
const buffer = canvas.toBuffer("image/png");
|
||||
fs.writeFileSync(outputPath, buffer);
|
||||
|
||||
console.log(`Green screen removed and saved to ${outputPath}`);
|
||||
};
|
||||
execSync(`ffmpeg -i ${process.env.VIDEO_FILE} assets/dice/frames/frame_%04d.png`, { stdio: 'inherit' })
|
||||
execSync(
|
||||
`ffmpeg -i ${process.env.VIDEO_FILE} assets/dice/frames/frame_%04d.png`,
|
||||
{ stdio: "inherit" },
|
||||
);
|
||||
// Usage
|
||||
let frames = readdirSync("assets/dice/frames");
|
||||
;(async () => {
|
||||
for(const frame of frames){
|
||||
if(!existsSync(`assets/dice/frames/cleaned_${frame}`)){
|
||||
await removeGreenScreen(`assets/dice/frames/${frame}`, `assets/dice/frames/cleaned_${frame}`)
|
||||
} else {
|
||||
console.log(`Skipping ${frame}`)
|
||||
}
|
||||
(async () => {
|
||||
for (const frame of frames) {
|
||||
if (!existsSync(`assets/dice/frames/cleaned_${frame}`)) {
|
||||
await removeGreenScreen(
|
||||
`assets/dice/frames/${frame}`,
|
||||
`assets/dice/frames/cleaned_${frame}`,
|
||||
);
|
||||
} else {
|
||||
console.log(`Skipping ${frame}`);
|
||||
}
|
||||
console.log(`Compiling frames into video`)
|
||||
execSync(`ffmpeg -framerate 30 -i assets/dice/frames/cleaned_frame_%04d.png -c:v libx264 -pix_fmt yuva420p ${process.env.OUT_FILE}`, { stdio: 'inherit' })
|
||||
console.log(`Done`)
|
||||
})()
|
||||
}
|
||||
console.log(`Compiling frames into video`);
|
||||
execSync(
|
||||
`ffmpeg -framerate 30 -i assets/dice/frames/cleaned_frame_%04d.png -c:v libx264 -pix_fmt yuva420p ${process.env.OUT_FILE}`,
|
||||
{ stdio: "inherit" },
|
||||
);
|
||||
console.log(`Done`);
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue