-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
44 lines (37 loc) · 838 Bytes
/
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
'use strict'
const ffmpeg = require('fluent-ffmpeg')
const noop = () => { }
module.exports = (opts) => {
const {
log = noop,
quality = 2,
offset = 0,
input,
output,
noaccurate = false
} = opts
return new Promise((resolve, reject) => {
const cmd = ffmpeg(input)
const inputOptions = []
if (noaccurate) {
inputOptions.push('-ss', offset / 1000)
} else {
cmd.seek(offset / 1000)
}
if (noaccurate) {
inputOptions.push('-noaccurate_seek')
}
const outputOptions = [
'-vframes', 1,
'-q:v', quality
]
cmd
.inputOptions(inputOptions)
.outputOptions(outputOptions)
.output(output)
.on('start', (cmd) => log && log({cmd}))
.on('end', () => resolve())
.on('error', (err) => reject(err))
.run()
})
}