Androz2091 / discord-player

🎧 Complete framework to simplify the implementation of music commands using discord.js v14
https://discord-player.js.org/
MIT License
605 stars 191 forks source link

error with large tracks #1761

Closed joaokristani closed 1 year ago

joaokristani commented 1 year ago

Describe the bug the error happens when i put a very big song ex: https://www.youtube.com/watch?v=wQxiaLQ2Evc it sounds like it has finished all the songs and disconnects before it gave this error Could not extract stream for this track but now it doesn't even show an error

To Reproduce Steps to reproduce the behavior:

Expected behavior i expected him to play the song

Screenshots there's nothing to show

Please complete the following information:

mariusbegby commented 1 year ago

I experience this issue as well, here's debug log from the example URL provided by @joaokristani:

Player debug event: Player triggered for Track {"title":"12 Horas de Músicas para Dormir-Relaxar-Trabalhar-Meditar","reason":"normal"}
Player debug event: state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
Player debug event: [NW] [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":634505}}
Player debug event: [NW] [WS] >> {"op":5,"d":{"speaking":0,"delay":0,"ssrc":634505}}
Player debug event: Track {"title":"12 Horas de Músicas para Dormir-Relaxar-Trabalhar-Meditar","isTransitionMode":false} was marked as finished
Player debug event: Adding track to history and emitting finish event since transition mode is disabled...
Player debug event: No more tracks left in the queue to play and repeat mode is off, initiating #emitEnd()
Player debug event: state change:
from {"status":"playing","missedFrames":0,"playbackDuration":400,"resource":true,"stepTimeout":false}
to {"status":"idle","resource":false,"stepTimeout":false}

Notice playbackDuration is only 400 ms. It starts playing, for 400 ms, then stops suddenly and initiating emitEnd(). Another example is URL https://www.youtube.com/watch?v=GqeVYOUSGUg which also has this same issue. I've tested this both on my local dev environment and in my production server, both experiencing the same issue. Ubuntu 22.04 LTS w/ ffmpeg 4.4.2-0ubuntu0.22.04.1 installed locally (no package). On Windows I use ffmpeg version 6.0-full_build. YouTube videoes with same codecs as these songs also work fine.

I've only experienced this issue with YouTube videos. Trying to debug this myself, but there's no error emitted from what I see.

mariusbegby commented 1 year ago

Also happens with latest version @discord-player/extractor v4.4.0 and discord-player v6.6.1.

Changing useLegacyFFmpeg to true/false does not change anything. Also here's some additional dependency info:

Discord Player
--------------------------------------------------
- discord-player: 6.6.1
- @discordjs/voice: 0.16.0
- discord.js: 14.11.0
- Node version: v18.16.0 (Detected Runtime: Node)
- ffmpeg: 6.0-full_build-www.gyan.dev
- command: ffmpeg
- static: false
- libopus: true

Loaded Extractors:
--------------------------------------------------
com.discord-player.spotifyextractor
com.discord-player.applemusicextractor
com.discord-player.soundcloudextractor
com.discord-player.youtubeextractor
com.discord-player.vimeoextractor
com.discord-player.reverbnationextractor
com.discord-player.attachmentextractor

@discordjs/voice
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.16.0
- prism-media: 1.3.5

Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: not found

Encryption Libraries
- sodium-native: not found
- sodium: not found
- libsodium-wrappers: 0.7.11
- tweetnacl: not found

FFmpeg
- version: 6.0-full_build-www.gyan.dev
- libopus: yes
--------------------------------------------------
twlite commented 1 year ago

This definitely seems to be an issue with ffmpeg streaming. Manually streaming works without any issues. Here is an example of manual streaming using yt-stream, but you can use any other streaming lib if needed.

import { onBeforeCreateStream } from 'discord-player';

onBeforeCreateStream(async (track) => {
    if (track.source === 'youtube') {
        return (
            await stream(track.url, {
                type: 'audio',
                quality: 'high',
                highWaterMark: 1 << 25
            })
        ).stream;
    }

    return null;
});
retrouser955 commented 1 year ago

This definitely seems to be an issue with ffmpeg streaming. Manually streaming works without any issues. Here is an example of manual streaming using yt-stream, but you can use any other streaming lib if needed.

import { onBeforeCreateStream } from 'discord-player';

onBeforeCreateStream(async (track) => {
    if (track.source === 'youtube') {
        return (
            await stream(track.url, {
                type: 'audio',
                quality: 'high',
                highWaterMark: 1 << 25
            })
        ).stream;
    }

    return null;
});

Could this be an issue with the way Discordjs/voice fetches stream urls?

twlite commented 1 year ago

This issue is not related to discordjs/voice as stream url never reaches it.

mariusbegby commented 1 year ago

@skdhg

This definitely seems to be an issue with ffmpeg streaming. Manually streaming works without any issues. Here is an example of manual streaming using yt-stream, but you can use any other streaming lib if needed.

import { onBeforeCreateStream } from 'discord-player';

onBeforeCreateStream(async (track) => {
    if (track.source === 'youtube') {
        return (
            await stream(track.url, {
                type: 'audio',
                quality: 'high',
                highWaterMark: 1 << 25
            })
        ).stream;
    }

    return null;
});

Using import { stream } from 'yt-stream' and this snippet:

onBeforeCreateStream: onBeforeCreateStream(
    async (track) => {
        if (track.source === 'youtube') {
            return (
                await stream(track.url, {
                    type: 'audio',
                    quality: 'high',
                    highWaterMark: 1 << 25
                })
            ).stream;
        }

        return null;
    }
)

Solved the issue with URL https://www.youtube.com/watch?v=GqeVYOUSGUg, but the issue is still apparent in URL https://www.youtube.com/watch?v=wQxiaLQ2Evc.

retrouser955 commented 1 year ago

This is possibly an issue with manual fetching of yt-stream url. The issue is probably here https://github.com/Androz2091/discord-player/blob/master/packages/extractor/src/extractors/common/helper.ts#L109