-
Notifications
You must be signed in to change notification settings - Fork 3
/
createSpriteImage.js
51 lines (42 loc) · 1.21 KB
/
createSpriteImage.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
const generateVideoScreenshots = require('./generateVideoScreenshots');
const joinImages = require('./joinImages');
const fs = require('fs-extra');
async function generateSpriteImage(
{
columns,
videoPath,
screenshotIntervalInSeconds,
sizeAsWidthxHeight,
outputFolder,
spriteOutputFilePath,
debug
}){
try {
const screenshotImagesFolder = `${outputFolder}/screenshotImages`;
// make screenshot folder if it doesn't exist
fs.mkdirSync(screenshotImagesFolder, { recursive: true });
// empty old folder and generate screenshots
fs.emptyDirSync(screenshotImagesFolder)
// use ffmpeg to take all the screenshot images
const response = await generateVideoScreenshots({
path: videoPath,
fps: (1 / screenshotIntervalInSeconds),
size: sizeAsWidthxHeight,
outputFolder: screenshotImagesFolder,
debug
})
c.l(response);
// do a horizontal and then vertical join
const spriteResponse = await joinImages({
columns,
outputPath: outputFolder,
spriteOutputFilePath,
debug
})
c.l(spriteResponse);
return spriteResponse
} catch (err){
console.log(err)
}
}
module.exports = generateSpriteImage;