Potential FFMPEG process fix (#381)

I am by no means sure that this will work. This is an experimental fix.
Please review it carefully; I’m not the best at working with
audio/streams.
This commit is contained in:
Programmix
2016-05-27 23:09:16 -07:00
committed by abalabahaha
parent e912c72a95
commit 2194632b7d
4 changed files with 118 additions and 171 deletions

View File

@@ -91,34 +91,7 @@ var AudioEncoder = (function () {
stream.pipe(enc.stdin);
var ffmpegErrors = "";
enc.stdout.pipe(_this.volume);
enc.stderr.on("data", function (data) {
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
});
enc.once("exit", function (code, signal) {
if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors));
}
});
_this.volume.once("readable", function () {
resolve({
proc: enc,
stream: _this.volume,
instream: stream,
channels: 2
});
});
_this.volume.on("end", function () {
reject("end");
});
_this.volume.on("close", function () {
reject("close");
});
hookEncodingProcess(resolve, reject, enc, stream);
});
};
@@ -130,33 +103,7 @@ var AudioEncoder = (function () {
var enc = _child_process2["default"].spawn(_this2.getCommand(), ['-i', file, '-f', 's16le', '-ar', '48000', '-ss', options.seek || 0, '-ac', 2, 'pipe:1']);
var ffmpegErrors = "";
enc.stdout.pipe(_this2.volume);
enc.stderr.on("data", function (data) {
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
});
enc.once("exit", function (code, signal) {
if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors));
}
});
_this2.volume.once("readable", function () {
resolve({
proc: enc,
stream: _this2.volume,
channels: 2
});
});
_this2.volume.on("end", function () {
reject("end");
});
_this2.volume.on("close", function () {
reject("close");
});
hookEncodingProcess(resolve, reject, enc);
});
};
@@ -170,33 +117,60 @@ var AudioEncoder = (function () {
var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
var enc = _child_process2["default"].spawn(_this3.getCommand(), options);
var ffmpegErrors = "";
hookEncodingProcess(resolve, reject, enc);
});
};
enc.stdout.pipe(_this3.volume);
enc.stderr.on("data", function (data) {
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
});
enc.once("exit", function (code, signal) {
if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors));
}
});
AudioEncoder.prototype.hookEncodingProcess = function hookEncodingProcess(resolve, reject, enc, stream) {
var _this4 = this;
_this3.volume.once("readable", function () {
resolve({
proc: enc,
stream: _this3.volume,
channels: 2
});
});
var processKilled = false;
_this3.volume.on("end", function () {
reject("end");
});
function killProcess() {
if (processKilled) return;
_this3.volume.on("close", function () {
reject("close");
});
enc.stdin.pause();
enc.kill("SIGINT");
processKilled = true;
}
var ffmpegErrors = "";
enc.stdout.pipe(this.volume);
enc.stderr.on("data", function (data) {
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
});
enc.once("exit", function (code, signal) {
if (code) {
reject(new Error("FFMPEG: " + ffmpegErrors));
}
});
this.volume.once("readable", function () {
var data = {
proc: enc,
stream: _this4.volume,
channels: 2
};
if (stream) {
data.instream = stream;
}
resolve(data);
});
this.volume.on("end", function () {
killProcess();
reject("end");
});
this.volume.on("close", function () {
killProcess();
reject("close");
});
};