-
Notifications
You must be signed in to change notification settings - Fork 1
/
ffmpeg.js
43 lines (40 loc) · 1.12 KB
/
ffmpeg.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
const ffmpeg = require('fluent-ffmpeg')
function split(project, fileName = 'input.mp4') {
return new Promise((resolve, reject) => {
ffmpeg(`./projects/${project}/${fileName}`)
.on('start', function (commandLine) {
console.log('Spawned Ffmpeg with command: ' + commandLine)
})
.on('error', function (err) {
console.log('An error occurred: ' + err.message)
reject(err)
})
.on('end', function () {
console.log('Processing finished !')
resolve()
})
.save(`./projects/${project}/video/%06d.png`)
})
}
function join(project, framerate) {
return new Promise((resolve, reject) => {
ffmpeg()
.input(`./projects/${project}/out/%06d.png`)
.inputFPS(framerate)
.outputFPS(framerate)
.videoCodec('copy')
.on('start', function (commandLine) {
console.log('Spawned Ffmpeg with command: ' + commandLine)
})
.on('error', function (err) {
console.log('An error occurred: ' + err.message)
reject(err)
})
.on('end', function () {
console.log('Processing finished !')
resolve()
})
.save(`./projects/${project}/output.mp4`)
})
}
module.exports = { join, split }