Fix arbitrary ffmpeg

This commit is contained in:
abalabahaha
2016-10-02 12:44:59 +09:00
parent c00d209014
commit 76dd4f74da
4 changed files with 28 additions and 22 deletions

View File

@@ -107,9 +107,9 @@ export default class AudioEncoder {
});
}
encodeArbitraryFFmpeg(ffmpegOptions, volume) {
encodeArbitraryFFmpeg(ffmpegOptions, options) {
return new Promise((resolve, reject) => {
this.volume = new VolumeTransformer(volume);
this.volume = new VolumeTransformer(options.volume);
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.'));
// add options discord.js needs
var options = ffmpegOptions.concat([
var ffmpegOptions = ffmpegOptions.concat([
'-f', 's16le',
'-ar', '48000',
'-ac', 2,
'pipe:1'
]);
var enc = cpoc.spawn(command, options);
var enc = cpoc.spawn(command, ffmpegOptions);
this.hookEncodingProcess(resolve, reject, enc);
});

View File

@@ -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;
self.stopPlaying();
if (typeof volume === "function") {
// volume is the callback
callback = volume;
}
if (!ffmpegOptions instanceof Array) {
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) => {
this.encoder
.encodeArbitraryFFmpeg(ffmpegOptions, volume)
.encodeArbitraryFFmpeg(ffmpegOptions, options)
.catch(error)
.then(data => {
self.streamProc = data.proc;