-
Notifications
You must be signed in to change notification settings - Fork 245
/
desktop.js
91 lines (82 loc) · 2.83 KB
/
desktop.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var logger = require('winston');
var configuration_handler = require('../handlers/configuration-handler');
var config = configuration_handler.initializeConfiguration();
exports.transcode = function(mediaID, type, response, url, file, outputPath, ExecConfig, CurrentTranscodings) {
var TRANSCODING_OPTS = [
'-threads 0',
'-vcodec libx264',
'-coder 0',
'-flags -loop',
'-pix_fmt yuv420p',
'-subq 0',
'-sc_threshold 0',
'-profile:v baseline',
'-keyint_min 150',
'-deinterlace -maxrate 10000000',
'-bufsize 10000000',
'-acodec aac',
'-strict experimental',
'-frag_duration 1000',
'-movflags +frag_keyframe+empty_moov'
];
if (config.quality === 'lossless') {
TRANSCODING_OPTS = TRANSCODING_OPTS.concat([
'-crf 0',
]);
} else if (config.quality === 'high' || config.quality === undefined) {
TRANSCODING_OPTS = TRANSCODING_OPTS.concat([
'-g 52',
'-crf 22',
'-ar 48000',
'-ab 320k',
]);
} else if (config.quality === 'medium') {
TRANSCODING_OPTS = TRANSCODING_OPTS.concat([
'-g 52',
'-crf 25',
'-s 1280x720',
'-ar 48000',
'-ab 192k',
]);
} else if (config.quality === 'low') {
TRANSCODING_OPTS = TRANSCODING_OPTS.concat([
'-g 52',
'-crf 30',
'-s 720x480',
'-ar 48000',
'-ab 128k',
]);
}
var transcodingOpts = TRANSCODING_OPTS.join(" ");
var ffmpeg = 'ffmpeg -i "' + url + '" ' + transcodingOpts + ' "' + outputPath + '"';
if (CurrentTranscodings.isTranscoding(url)) {
logger.info('Already transcoding', url);
} else {
var exec = require('child_process').exec;
var child = exec(ffmpeg, ExecConfig, function (err, stdout, stderr) {
if (err) {
logger.error('FFMPEG error: ', err);
} else {
logger.info('Transcoding complete');
CurrentTranscodings.remove(url);
var progData = { EpisodeId : mediaID };
if (type === 'Movie') {
progData = { MovieId : mediaID };
}
ProgressionMarker.find({ where: progData }).then(function (marker) {
marker.updateAttributes({ transcodingStatus : 'done' });
});
}
});
CurrentTranscodings.add(child, url);
child.stdout.on('data', function (data) {
logger.info(data.toString());
});
child.stderr.on('data', function (data) {
logger.warn(data.toString());
});
child.on('exit', function () {
CurrentTranscodings.remove(url);
});
}
};