-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (46 loc) · 1.47 KB
/
index.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
'use strict'
const probe = require('./src/probe')
const makeImages = require('./src/make-images')
const stitchImages = require('./src/stitch-images')
const makeDir = require('./src/make-dir')
const mergeClips = require('./src/merge-clips')
const cleanup = require('./src/cleanup')
const { sep } = require('path')
async function makePreview({input, hash, output}) {
const segments = 8
const delay = 20
const length = await probe(input)
const segmentLength = length / segments - delay;
const duration = 2
const range = []
const snapDir = 'snapshots'
const workDir = `${__dirname}${sep}${snapDir}${sep}${hash}`
const destDir = output || 'clips'
if (length < delay) {
return
}
await makeDir(workDir)
for (let i = 0; i < segments; i += 1) {
range.push(i)
}
const jobs = range.map(i => {
return new Promise(async (resolve) => {
await makeDir(`${workDir}${sep}${i}`)
await makeImages({
input,
segment: i,
start: delay + (segmentLength * i) - duration,
duration,
workDir
})
await stitchImages(i, workDir)
resolve()
})
})
return Promise.all(jobs).then(async () => {
console.log('All jobs done')
await mergeClips(range.map(i => `${workDir}${sep}clip${i}.mp4`), workDir, destDir, hash)
cleanup(workDir)
})
}
module.exports = makePreview