-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
63 lines (56 loc) · 1.68 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { program } from "commander";
import ffmpeg from "fluent-ffmpeg";
import path from "path";
program
.name("100x-uploader")
.description(
"Takes a video create a watermarked version of it trnascodes and uploades to bunny"
);
program
.command("convert")
.description("Convert a normal video to a watermarked version of it")
.option("--video <path>", "path to the video")
.option("--image <path>", "path to the watermark image")
.action((options) => {
const inputVideo = options.video;
const watermarkImage = options.image;
if (!inputVideo || !watermarkImage) {
console.error("Both --video and --image options are required");
process.exit(1);
}
const outputVideo = path.join(
path.dirname(inputVideo),
`${path.basename(
inputVideo,
path.extname(inputVideo)
)}_watermarked${path.extname(inputVideo)}`
);
let count = 0;
ffmpeg(inputVideo)
.input(watermarkImage)
.complexFilter([
{
filter: "overlay",
options: { x: "main_w-overlay_w-10", y: "main_h-overlay_h-10" }, // bottom-right corner with 10px margin
},
])
.output(outputVideo)
.on("start", (cmd) => {
console.log(`Executing: ${cmd}`);
})
.on("progress", (progress) => {
count++;
if (count % 5 === 0) return;
console.log(`Processing: ${progress.percent.toFixed(1)}% done`);
})
.on("end", () => {
console.log(
`Watermark added successfully! Output file: ${outputVideo}`
);
})
.on("error", (err) => {
console.error("Error occurred:", err);
})
.run();
});
program.parse(process.argv);