youtube-audio-stream
youtube-audio-stream copied to clipboard
Live Videos
Hello,
thank you for that awesome library. For normal youtube videos, everything works fine, it goes like a clockwork. But streaming live videos from youtube produces many audio artifacts. Frequently, there are hearable interruptions in the stream.
Can anyone reproduce that problem?
Thanks
Hello.
Yes, I found that to be the case as well.
The following code produces a stream that will consistently play 3 seconds of audio, but then stop abruptly.
const stream = require('youtube-audio-stream');
const app = require('express')();
app.get('/audio/:id', (req, res) => {
const youtubeUrl = 'http://youtube.com/watch?v=' + req.params.id;
try {
youtubeStream(youtubeUrl).pipe(res);
} catch (ex) {
res.status(500).send(ex);
}
});
// etc...
When the youtube ID is a live video, this issue occurs. With normal videos, it works fine.
Can confirm live also ends abruptly after 4 seconds of audio for me Streaming YouTube live would be great feature though +1
It's probably related to me not having time to update ytdl-core manually... (This has now been automated).
Can you test again with the latest version please?
It's probably related to me not having time to update ytdl-core manually... (This has now been automated).
Can you test again with the latest version please?
Hello, I have installed the latest version, with live videos it stops after 3 seconds of playback. Amazing library!
Is there a workaround to this?
Apparently the root of the problem is related to the configs passed to ytdl-core, which has a lot of similar reported issues of livestreams not working properly. A solution posted there that worked for me was this:
https://github.com/fent/node-ytdl-core/issues/1015#issuecomment-1037889998
These settings need to be set directly as the opt
object in the index.js
file of the youtube-audio-stream
package:
// youtube-audio-stream/index.js
function streamify (uri, opt) {
// opt = {
// ...opt,
// videoFormat: 'mp4',
// quality: 'lowest',
// audioFormat: 'mp3',
// filter (format) {
// return format.container === opt.videoFormat && format.audioBitrate
// }
// }
opt = {
videoFormat: 'mp4',
audioFormat: 'mp3',
quality: [91, 92, 93, 94, 95],
liveBuffer: 4900,
}
const video = ytdl(uri, opt)
.
.
.