-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextFrame.js
63 lines (51 loc) · 1.55 KB
/
nextFrame.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
//
// This module extracts the next frame from the movie into ./public/frame.png
//
const storage = require("node-persist");
const ffmpeg = require("fluent-ffmpeg");
var totalFrames;
var currentFrame;
var movieFile;
var frameRate;
async function main() {
await storage.init({
dir: "./config"
});
totalFrames = await storage.getItem("totalFrames");
currentFrame = await storage.getItem("currentFrame");
frameRate = await storage.getItem("frameRate");
movieFile = await storage.getItem("movieFile");
console.log(movieFile);
// console.log(frameRate);
const cmd = ffmpeg(movieFile);
// 1000 * (current /fps) = will result in the number of milliseconds
// want to special case the 1st frame (0) to avoid div by zero
var milliseconds = 0;
if (currentFrame != 0) {
milliseconds = 1000 * (currentFrame / frameRate);
}
// timestamp is in [[hh:]mm:]ss[.xxx]) -- we have fps and total frames.
var date = new Date(milliseconds);
var timeStamp =
date.getUTCHours() +
":" +
("0" + date.getUTCMinutes()).slice(-2) +
":" +
("0" + date.getUTCSeconds()).slice(-2) +
"." +
("00" + date.getUTCMilliseconds()).slice(-3);
console.log(timeStamp + " " + currentFrame + "/" + totalFrames);
cmd.screenshots({
timestamps: [timeStamp],
filename: "frame.png",
folder: "./public/"
});
// Move to the next frame
currentFrame++;
// check to see if currentFrame > totalFrame and fix it
if (currentFrame > totalFrames) {
currentFrame = 0;
}
await storage.setItem("currentFrame", currentFrame);
}
main();