You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
969 B
40 lines
969 B
2 years ago
|
import ffmpeg from "fluent-ffmpeg";
|
||
|
import path from "path";
|
||
|
|
||
|
export const description = "Generates a thumbnail of a specific size from a video."
|
||
|
|
||
|
export const options = [
|
||
|
["--input <file>", "input file video"],
|
||
|
["--start <time>", "starting position", 600],
|
||
|
["--output <file>", "output filename, ext will determine type"],
|
||
|
["--debug <level>", "debug level for ffmpeg, 1=command, 2=all"]
|
||
|
];
|
||
|
|
||
|
export const main = (opts) => {
|
||
|
const { dir, name } = path.parse(opts.input);
|
||
|
|
||
|
const encode = ffmpeg(opts.input)
|
||
|
.inputOptions([
|
||
|
"-ss", opts.start
|
||
|
])
|
||
|
.outputOptions([
|
||
|
"-frames:v", 1,
|
||
|
"-vsync", "vfr"
|
||
|
])
|
||
|
.on("end", () => process.exit(0));
|
||
|
|
||
|
if(opts.output) {
|
||
|
encode.output(opts.output);
|
||
|
} else {
|
||
|
encode.output(`${dir}/${name}.jpg`);
|
||
|
}
|
||
|
|
||
|
if(opts.debug === 1) {
|
||
|
encode.on("start", line => console.log(line))
|
||
|
} else if(opts.debug === 2) {
|
||
|
encode.on("stderr", line => console.log(line))
|
||
|
}
|
||
|
|
||
|
encode.run();
|
||
|
}
|