【问题标题】:Node.js - I keep getting the following error: Error: ffmpeg stream: write EPIPENode.js - 我不断收到以下错误:错误:ffmpeg 流:写入 EPIPE
【发布时间】:2020-06-20 23:25:32
【问题描述】:

我目前正在使用 discord.js 编写 Discord 机器人,并且正在使用 ytdl-core 播放音乐。这是我用来播放音乐的程序:

const {google} = require('googleapis');
const ytdl = require('ytdl-core');
// Initialise Google API
const youtube = google.youtube({
    version: 'v3',
    auth: MyAuth
});
musicQueue = [] // Queue for playing music
dispatcher = null; // Transmits voice packets from stream

module.exports = {
    name: "play",

    async execute(msg, args) { // msg is a Discord Message
        // Play music and music queued after
        async function playAndQueue(stream) {

            // Join voice channel
            voiceChannel = client.channels.cache.find(channel => channel.type === "voice" && channel.name === "music-channel");
            voiceConnection = voiceChannel.join();

            dispatcher = await voiceConnection.play(stream, {volume: 0.3}); // Decrease volume to prevent clipping

            // When music stops
            dispatcher.on("finish", async reason => {
                if (musicQueue[0]) { // Still have music queued
                    const nextVideoLink = musicQueue[0]; // Next video to play
                    const stream = ytdl(nextVideoLink, {filter: 'audioonly'});

                    playAndQueue(stream);
                    dispatcherInfo = await ytdl.getInfo(nextVideoLink);
                    musicQueue.shift();
                } else { // No music to play
                    dispatcher = null;
                    dispatcherInfo = null;
                }
            });

            dispatcher.on("error", console.log);
            dispatcher.on("debug", console.log);

        }

        // Search Youtube using args
        const youtubeSearchResult = await youtube.search.list({
            part: 'snippet',
            type: 'video', // We do not want channels or playlists
            q: args.join(' '),
            maxResults: 1 // We only need first search result
        });
        const youtubeVideo = youtubeSearchResult.data.items[0];
        if (! youtubeVideo) {
            msg.channel.send("Error: Could not find any music matching search.");
            return;
        }

        const videoLink = `https://www.youtube.com/watch?v=${youtubeVideo.id.videoId}`; // Link to video

        const stream = ytdl(videoLink, {filter: 'audioonly'});
        const videoInfo = await ytdl.getInfo(videoLink);


        if (dispatcher) { // Currently playing music
            musicQueue.push(videoLink);
            msg.channel.send(`**${videoInfo.title}** has been added into the queue!`);
        } else {
            playAndQueue(stream);
            dispatcherInfo = videoInfo;
            msg.channel.send(`Currently playing **${videoInfo.title}**!`);
        }
    }
}

但是,当我尝试在 Heroku 上运行该程序时,我收到此错误:

ffmpeg stream: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete (internal/stream_base_commons.js:92:16) {
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write'
}

我能做什么?

【问题讨论】:

标签: node.js heroku ffmpeg google-api discord.js


【解决方案1】:

为了将来可能对某人有所帮助的文档,我遇到了类似的 EPIPE 错误:

(WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16) { errno: 'EPIPE', code: 'EPIPE', syscall: 'write')} 

我在带有 ffmpeg/fluent-ffmpeg/editly 的 ubuntu/docker nodeJS 应用程序上使用 FFmpeg。基本上发生这个错误是因为我的音频流没有视频文件那么长。

【讨论】:

    【解决方案2】:

    经过一番挖掘,我最终发现错误是我在另一个函数中调用dispatcher.destroy()时发生的。我用dispatcher.end() 替换了代码,解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 2016-04-25
      • 1970-01-01
      • 2021-04-23
      • 2021-02-02
      • 2019-01-21
      • 2014-04-15
      • 2015-08-17
      • 2012-02-04
      相关资源
      最近更新 更多