fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.53k stars 802 forks source link

Stream is terminated 10 - 15 seconds before the end of the video #402

Closed TotomInc closed 4 years ago

TotomInc commented 5 years ago

It's been 1 month since users have been reporting that YouTube videos are not played entirely.

The bot often stops 10 - 15 seconds before the end of a video. I don't have any particular error thrown by ytdl nor by discord.js.

When I log the reason of a voice-connection ending is Stream is not generating quickly enough.. I really doubt this is a low bandwidth issue since the bot is hosted on a Google Cloud Platform VM with 400 mbps up/down.

What I'm doing with YTDL:

export function getReadableStream(track: models.Track): Readable {
  return YTDL(track.streamURL, { filter: 'audioonly' });
}

From this code snippet, I store the result of the function and play the stream with discord.js:

guildVoiceConnection.playStream(stream, streamOptions)
    .on('end', (reason) => _onTrackEnd(reason, message));

The bot is open-source if you want to dig-up more code.

I've also opened an issue on the repo of the bot.

EDIT : see @COPS2000 answer for a working fix

BrotalityG commented 5 years ago

So I dont know if you all fixed it on your ends but in my code I put

const dispatcher = serverQueue.connection.playStream(ytdl(song.url, {
        filter: "audioonly",
        highWaterMark: 1<<25
    }))

and that fixed it on the most recent YTDL version. I no longer have any of that happening and my bot is back to working perfectly.

JMTK commented 5 years ago

@COPS2000 I will put on a large playlist and report back.

EDIT: After over an hour of nonstop playing, seems to be working.

TotomInc commented 5 years ago

@COPS2000 How does it work with long tracks?

IIRC, highWaterMark option with an high value cause some issues with long tracks which are at least 1 hour long. The track would stop in the middle or around the end of the video.

Can you please test with only 1 long video, and not a playlist?

Thanks! :smile:

JMTK commented 5 years ago

It's my understanding that the higher the highWaterMark, the more it downloads, so maybe just double the value. There might be a way to use the info return value to calculate the video size so when you go to download it with the highWaterMark, you can give an accurate value.

fent commented 3 years ago

py files? this is a node.js project