-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-hover-thumbnail-cli.js
60 lines (48 loc) · 1.86 KB
/
generate-hover-thumbnail-cli.js
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
const { program } = require('commander');
const fs = require('fs');
const generateHoverThumbnail = require('./generateHoverThumbnail');
program
.description('Takes a path to a video and outputs a .webp file that is a 5 second thumbnail at 2x speed (2.5 seconds total)')
.requiredOption('-i, --inputFilePath <type>', 'Path to the video that the .webp hover thumbnail will be created for')
.requiredOption('--outputFolder <type>', 'Path to the folder where the hover thumbnail .webp file will be outputted')
.requiredOption('--filename <type>', 'Filename to be declared (so it will output ${filename}.webp at the outputPath')
.option('--quality <type>', 'Quality of the .webp from 1 to 100 (100 is full quality)')
.option('--framerate <type>', 'Framerate to be used in the .webp')
.option('--height <type>', 'Height in pixels')
.option('--width <type>', 'Width in pixels')
.option('--debug', 'Logs a bunch of stuff and preserves the files as they\'re created')
program.parse();
const options = program.opts();
const {
inputFilePath,
filename,
outputFolder,
debug,
quality,
framerate,
height,
width
} = options;
fs.mkdirSync(outputFolder, { recursive: true });
if(debug){
console.log(`inputFilePath: ${inputFilePath}`)
console.log(`filename: ${filename}`)
console.log(`outputFolder: ${outputFolder}`)
console.log(`debug: ${debug}`)
}
generateHoverThumbnail({
inputFilePath,
filename,
outputFolder,
debug,
framerate,
quality,
height,
width
})
// Example to use:
// Without debug
// $ node generate-hover-thumbnail-cli.js --inputFilePath './examples/assets/video.mp4' --outputFolder './examples/assets' --filename video
// With debug (logs and processed files)
// $ node generate-hover-thumbnail-cli.js --inputFilePath './examples/assets/video.mp4' --outputFolder './examples/assets' --filename video --debug
// cd examples && http-server -c-1