-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtsp_handler.js
47 lines (43 loc) · 1.16 KB
/
rtsp_handler.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
// ffmpeg -i url -vframes 1 input.jpg
// -y: Overwrite output files without asking
// -i: URL
const fs = require('fs')
const ffmpeg = require('fluent-ffmpeg')
const Jimp = require('jimp')
const run = (url, onError, onSuccess, onDone) => {
ffmpeg(url)
.frames(1)
.format('image2')
.on('stderr', (stderrLine) => {
console.log('Stderr output: ' + stderrLine)
})
.on('error', (err, stdout, stderr) => {
console.log('Cannot process video: ' + err.message)
onError(err)
})
.on('end', () => {
console.log('Processing finished !')
onDone()
})
.pipe()
.on('data', (chunk) => {
console.log('ffmpeg just wrote ' + chunk.length + ' bytes')
onSuccess(chunk)
})
}
const runSync = (url) => {
return new Promise((resolve, reject) => {
let chunks = []
run(url, (err) => {
reject(err)
}, (chunk) => {
chunks.push(chunk)
}, () => {
Jimp.read(Buffer.concat(chunks)).then(jimp => resolve(jimp)).catch(err => {
console.log(err)
reject(err)
})
})
})
}
module.exports = runSync