Code:
function createStream(url, type, mode, options) {
let FFmpegArgs;
switch(mode) {
case '1': {
const inputStream = ytdl(url, options);
FFmpegArgs = [ '-reconnect', '1', '-reconnect_streamed', '1', '-reconnect_delay_max', '5', '-i', url, '-analyzeduration', '0', '-loglevel', '0', '-f', options && options.format && typeof options.format === 'string' ? options.format : 's16le', '-ar', '48000', '-ac', '2' ];
FFmpegArgs.concat(options.filters);
let transcoder = new prism.FFmpeg({ shell: false, args: FFmpegArgs });
const output = inputStream.pipe(transcoder);
if(options && !options.opusEncoded) {
for(const event of events) {
inputStream.on(event, (...args) => output.emit(event, ...args));
}
inputStream.on('error', error => transcoder.destroy(error));
output.on('close', () => transcoder.destroy());
console.log(output)
return output;
}
const opus = new prism.opus.Encoder({ rate: 48000, channels: 2, frameSize: 960 });
const outputStream = output.pipe(opus);
for (const event of events) {
inputStream.on(event, (...args) => outputStream.emit(event, ...args));
}
const _destroy = error => {
if (!transcoder.destroyed)
transcoder.destroy();
if (!opus.destroyed)
opus.destroy();
}
outputStream.on('close', _destroy).on('error', _destroy);
console.log(outputStream)
return outputStream;
}
case '2': {
//to be continued
}
}
}
Help me please. I have been suffering for 2 days (
P.S. Discord.js v13