-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvideo.js
48 lines (43 loc) · 1.15 KB
/
video.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
//
// Creates a mp4 based on a folder of images
//
var fs = require('fs');
var videoshow = require('videoshow')
let videoOptions = {
fps: 25,
loop: 0.1, // seconds
transition: false,
videoBitrate: 1024,
videoCodec: 'libx264',
size: '640x?',
format: 'mp4',
pixelFormat: 'yuv420p'
}
module.exports = (videoPath, imagesPath, imageFormat) => {
let currentDate = String(Date.now());
let validIimages = [];
videoPath = videoPath + currentDate + '.mp4';
fs.readdir(imagesPath, (err, files) => {
if (err) throw err;
files.forEach(function(file) {
if (file.indexOf(imageFormat) >= 0) {
validIimages.push(imagesPath + file);
}
})
validIimages.length > 0 && createVideo();
})
let createVideo = () => {
videoshow(validIimages, videoOptions)
.save(videoPath)
.on('start', function (command) {
console.log('ffmpeg process started:', command)
})
.on('error', function (err, stdout, stderr) {
console.error('Error:', err)
console.error('ffmpeg stderr:', stderr)
})
.on('end', function (output) {
console.error('Video created in:', output)
})
}
}