-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.js
80 lines (66 loc) · 3.06 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { program } = require('commander');
const fs = require('fs');
const createSpriteWithVTT = require('./index');
program
.description('Takes a video and creates a thumbnail sprite with corresponding vtt for progress preview thumbnails')
.requiredOption('-i, --input <type>', 'Path to the video that thumbnails will be created for')
.option('--outputFolder <type>', 'Path to the folder where the thumbnail sprite/s and vtt will be saved')
.option('--filename <type>', 'Name of the output files, by default it will be ${filename}_sprite.webp and ${filename}_sprite.vtt')
.option('--interval <type>', 'Integer representing the interval in seconds between screenshots (aka 2 is once every 2 seconds)', '2')
.option('--prependPath <type>', 'Used in the webvtt to build paths to where the sprite thumbnail/s will be served', '.')
.option('--thumbnailSize <type>', 'Instead of setting height/width (px), set the longest side and an algorithm will calculate the other', '140')
.option('--targetSize <type>', 'Targeted maximum size when splitting the sprite image, in kb', '80')
.option('--columns <type>', 'I don\'t know what difference it makes but you can change it', '9')
.option('--debug', 'Logs a bunch of stuff and preserves the files as they\'re created')
program.parse();
const options = program.opts();
const {
input: inputFilePath,
filename,
outputFolder,
prependPath,
debug,
interval: intervalInSecondsAsInteger,
thumbnailSize: thumbnailLongestSide,
targetSize: targetSizeInKb,
columns,
} = options;
// // output variables
const spriteFileName = `${filename}_sprite.webp`;
const vttFileName = `${filename}_sprite.vtt`;
fs.mkdirSync(outputFolder, { recursive: true });
// // where to output the files
const spriteOutputFilePath = `${outputFolder}/${spriteFileName}`;
const webVTTOutputFilePath = `${outputFolder}/${vttFileName}`;
if(debug){
console.log(`inputFile: ${inputFilePath}`)
console.log(`spriteOutputFilePath: ${spriteOutputFilePath}`)
console.log(`webVTTOutputFilePath: ${webVTTOutputFilePath}`)
console.log(`intervalInSecondsAsInteger: ${intervalInSecondsAsInteger}`)
console.log(`prependPath: ${prependPath}`)
console.log(`filename: ${filename}`)
console.log(`spriteFileName: ${spriteFileName}`)
console.log(`targetSizeInKb: ${targetSizeInKb}`)
console.log(`thumbnailLongestSide: ${thumbnailLongestSide}`)
console.log(`columns: ${columns}`)
}
createSpriteWithVTT({
inputFilePath,
filename,
spriteFileName,
spriteOutputFilePath,
webVTTOutputFilePath,
prependPath,
intervalInSecondsAsInteger: Number(intervalInSecondsAsInteger),
columns: Number(columns),
thumbnailLongestSide: Number(thumbnailLongestSide),
targetSizeInKb: Number(targetSizeInKb),
debug,
outputFileDirectory: outputFolder
})
// Example to use:
// Without debug
// $ node cli.js --input './examples/assets/video.mp4' --outputFolder './examples/assets' --filename video
// With debug (logs and processed files)
// $ node cli.js --input './examples/assets/video.mp4' --outputFolder './examples/assets' --filename video --debug
// cd examples && http-server -c-1