【发布时间】:2019-11-06 10:36:37
【问题描述】:
我正在尝试使用我的 discord 机器人播放音乐,我想使用 ffmpeg 指定音乐的开头,效果很好,但我只能使用 ffmpeg 下载音乐然后播放。我希望 ffmpeg 对其进行处理,然后将其流式传输以播放音乐。
这是我用来下载然后播放音乐的代码:
message.member.voiceChannel.join().then((con, err) => {
ytPlay.search_video(op, (id) => {
let stream = ytdl("https://www.youtube.com/watch?v=" + id, {
filter: "audioonly"
});
let audio = fs.createWriteStream('opStream.divx');
proc = new ffmpeg({
source: stream
})
proc.withAudioCodec('libmp3lame')
.toFormat('mp3')
.seekInput(35)
.output(audio)
.run();
proc.on('end', function() {
let input = fs.createReadStream('opStream.divx');
console.log('finished');
guild.queue.push(id);
guild.isPlaying = true;
guild.dispatcher = con.playStream(input);
});
});
})
是否可以做我想做的事,如果可以,怎么做?
【问题讨论】:
标签: javascript node.js ffmpeg discord.js fluent-ffmpeg