mirror of
https://github.com/danbulant/discord.js
synced 2026-07-05 19:20:42 +00:00
Fix arbitrary ffmpeg
This commit is contained in:
parent
c00d209014
commit
76dd4f74da
4 changed files with 28 additions and 22 deletions
|
|
@ -124,11 +124,11 @@ var AudioEncoder = (function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
AudioEncoder.prototype.encodeArbitraryFFmpeg = function encodeArbitraryFFmpeg(ffmpegOptions, volume) {
|
AudioEncoder.prototype.encodeArbitraryFFmpeg = function encodeArbitraryFFmpeg(ffmpegOptions, options) {
|
||||||
var _this3 = this;
|
var _this3 = this;
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
_this3.volume = new _VolumeTransformer2["default"](volume);
|
_this3.volume = new _VolumeTransformer2["default"](options.volume);
|
||||||
|
|
||||||
var command = _this3.getCommand();
|
var command = _this3.getCommand();
|
||||||
|
|
||||||
|
|
@ -136,8 +136,8 @@ var AudioEncoder = (function () {
|
||||||
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
||||||
|
|
||||||
// add options discord.js needs
|
// add options discord.js needs
|
||||||
var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
|
var ffmpegOptions = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
|
||||||
var enc = _child_process2["default"].spawn(command, options);
|
var enc = _child_process2["default"].spawn(command, ffmpegOptions);
|
||||||
|
|
||||||
_this3.hookEncodingProcess(resolve, reject, enc);
|
_this3.hookEncodingProcess(resolve, reject, enc);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -324,23 +324,26 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
VoiceConnection.prototype.playArbitraryFFmpeg = function playArbitraryFFmpeg(ffmpegOptions, volume) {
|
VoiceConnection.prototype.playArbitraryFFmpeg = function playArbitraryFFmpeg(ffmpegOptions, options) {
|
||||||
var _this3 = this;
|
var _this3 = this;
|
||||||
|
|
||||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2];
|
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2];
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
self.stopPlaying();
|
self.stopPlaying();
|
||||||
if (typeof volume === "function") {
|
|
||||||
// volume is the callback
|
|
||||||
callback = volume;
|
|
||||||
}
|
|
||||||
if (!ffmpegOptions instanceof Array) {
|
if (!ffmpegOptions instanceof Array) {
|
||||||
ffmpegOptions = [];
|
ffmpegOptions = [];
|
||||||
}
|
}
|
||||||
var volume = volume !== undefined ? volume : this.getVolume();
|
if (typeof options === "function") {
|
||||||
|
// options is the callback
|
||||||
|
callback = options;
|
||||||
|
}
|
||||||
|
if (typeof options !== "object") {
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
_this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions, volume)["catch"](error).then(function (data) {
|
_this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions, options)["catch"](error).then(function (data) {
|
||||||
self.streamProc = data.proc;
|
self.streamProc = data.proc;
|
||||||
self.instream = data.instream;
|
self.instream = data.instream;
|
||||||
var intent = self.playStream(data.stream);
|
var intent = self.playStream(data.stream);
|
||||||
|
|
|
||||||
|
|
@ -107,9 +107,9 @@ export default class AudioEncoder {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
encodeArbitraryFFmpeg(ffmpegOptions, volume) {
|
encodeArbitraryFFmpeg(ffmpegOptions, options) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.volume = new VolumeTransformer(volume);
|
this.volume = new VolumeTransformer(options.volume);
|
||||||
|
|
||||||
var command = this.getCommand();
|
var command = this.getCommand();
|
||||||
|
|
||||||
|
|
@ -117,13 +117,13 @@ export default class AudioEncoder {
|
||||||
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
||||||
|
|
||||||
// add options discord.js needs
|
// add options discord.js needs
|
||||||
var options = ffmpegOptions.concat([
|
var ffmpegOptions = ffmpegOptions.concat([
|
||||||
'-f', 's16le',
|
'-f', 's16le',
|
||||||
'-ar', '48000',
|
'-ar', '48000',
|
||||||
'-ac', 2,
|
'-ac', 2,
|
||||||
'pipe:1'
|
'pipe:1'
|
||||||
]);
|
]);
|
||||||
var enc = cpoc.spawn(command, options);
|
var enc = cpoc.spawn(command, ffmpegOptions);
|
||||||
|
|
||||||
this.hookEncodingProcess(resolve, reject, enc);
|
this.hookEncodingProcess(resolve, reject, enc);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -283,20 +283,23 @@ export default class VoiceConnection extends EventEmitter {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
playArbitraryFFmpeg(ffmpegOptions, volume, callback = function (err, str) { }) {
|
playArbitraryFFmpeg(ffmpegOptions, options, callback = function (err, str) { }) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.stopPlaying();
|
self.stopPlaying();
|
||||||
if (typeof volume === "function") {
|
|
||||||
// volume is the callback
|
|
||||||
callback = volume;
|
|
||||||
}
|
|
||||||
if (!ffmpegOptions instanceof Array) {
|
if (!ffmpegOptions instanceof Array) {
|
||||||
ffmpegOptions = [];
|
ffmpegOptions = [];
|
||||||
}
|
}
|
||||||
var volume = volume !== undefined ? volume : this.getVolume();
|
if (typeof options === "function") {
|
||||||
|
// options is the callback
|
||||||
|
callback = options;
|
||||||
|
}
|
||||||
|
if (typeof options !== "object") {
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.encoder
|
this.encoder
|
||||||
.encodeArbitraryFFmpeg(ffmpegOptions, volume)
|
.encodeArbitraryFFmpeg(ffmpegOptions, options)
|
||||||
.catch(error)
|
.catch(error)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
self.streamProc = data.proc;
|
self.streamProc = data.proc;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue