Unable to play more than a few seconds from a Youtube live stream
supergrov3r opened this issue · 5 comments
Hi all, I am unable to play more than 2-3 seconds of any live video (such as https://www.youtube.com/watch?v=5qap5aO4i9A). The stream ends without any errors. Normal videos are fine.
My code:
stream = await ytdl(track.url, { quality: 'highestaudio', filter: (track.isLive ? (format => format.isHLS === true) : (format => format.container === 'webm' && format.codecs === 'opus')), highWaterMark: 1<<10, liveBuffer: 5000, dlChunkSize: 1<<12 }); type = (track.isLive ? StreamType.Arbitrary : StreamType.WebmOpus);
This code using the above link will choose the itag 95 (720p video) format with isHLS=true from Youtube. I've also played around with the highWaterMark and dlChunkSize options but this doesn't change anything.
I'm using Node.js v16.9.1, Discord.js v13.1.0, @discordjs/voice v0.6.0 & ytdl-core v4.9.1.
Am I doing something wrong?
Adding more context - liveBuffer: 5000
or higher will result in only a few seconds playback, but liveBuffer: 4000
or even liveBuffer: 4900
will playback without issues...
🤔 liveBuffer
is a straight pass-through to the m3u8 module
might be worth opening an issue there
This is not a bug
@supergrov3r
I found something that works for me currently.
Like what you said, I set the liveBuffer: 4900
and set quality: [91, 92, 93, 94, 95]
I didn't set the filter because it throws an error. (maybe because quality is set to 91 through 95?, idk)
The reason I set the quality 91 through 95 is due to @fent 's comment in issue #166 .
Edit: So the code went like this.
const stream = ytdl("https://youtu.be/G72M3qnq58Q", {highWaterMark: 1<<25, quality: [91,92,93,94,95], liveBuffer: 4900})
Here is my solution to play normal YT url and LIVE YT url
async play_YT_url(url, begin_t) {
var data = await ytdl.getBasicInfo(url, {
requestOptions: {
headers: {
cookie: YT_COOKIE,
},
},
});
if (data.videoDetails.liveBroadcastDetails && data.videoDetails.liveBroadcastDetails.isLiveNow) {
this.audio_stream = ytdl(url, {
//filter: 'audioonly',
liveBuffer: 1000,
//highWaterMark: 1024,
//dlChunkSize: 65536,
quality: 'highestaudio',
//begin: begin_t,
requestOptions: {
headers: {
cookie: YT_COOKIE,
// Optional. If not given, ytdl-core will try to find it.
// You can find this by going to a video's watch page, viewing the source,
// and searching for "ID_TOKEN".
// 'x-youtube-identity-token': 1324,
},
},
});
} else {
this.audio_stream = ytdl(url, {
filter: 'audioonly',
//liveBuffer: 4000,
//highWaterMark: 1024,
dlChunkSize: 65536,
quality: 'highestaudio',
//begin: begin_t,
requestOptions: {
headers: {
cookie: YT_COOKIE,
// Optional. If not given, ytdl-core will try to find it.
// You can find this by going to a video's watch page, viewing the source,
// and searching for "ID_TOKEN".
// 'x-youtube-identity-token': 1324,
},
},
});
}
try {
this.play_stream(begin_t);
} catch (error) {
console.log("[Skipping]Can't play YT stream")
console.log(error);
this.next_song();
}
return;
}
Still doing tests, might optimize the value of livebuffer later