-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle.js
59 lines (39 loc) · 1.19 KB
/
handle.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
54
55
56
57
58
59
var fs = require('fs');
var async = require('async');
var videoUtils = require('./videoUtils');
var THREADS = 1;
//console.log(process.argv);
var prefix = process.argv.pop();
var files = fs.readdirSync('videos/' + prefix);
//console.log(files);
var regex = new RegExp('^\\d+\\.webm');
files = files.filter(function(f) {
var m = regex.exec(f);
var f2 = !!m;
regex.lastIndex = 0;
return f2;
});
var fileDataArr = files.map(function(f) {
return {
filePath: 'videos/' + prefix + '/' + f,
fileName: f
};
});
//console.log(fileDataArr);
function findVideoDuration2(fileData, cb) {
videoUtils.findVideoDuration(fileData.filePath, function(err, duration) {
if (err) { return cb(err); }
fileData.duration = duration;
cb(null, duration);
});
}
async.mapLimit(fileDataArr, THREADS, findVideoDuration2, function(err, durations) {
// console.log(err, durations);
videoUtils.computeStartTimes(fileDataArr);
async.mapLimit(fileDataArr, THREADS, videoUtils.webm2Mpegts, function(err, tsFiles) {
var playlistFp = 'videos/' + prefix + '/playlist.m3u8';
videoUtils.generateM3u8Playlist(fileDataArr, playlistFp, false, function(err) {
console.log(err ? err : 'ALL DONE!');
});
});
});