Friday 28 January 2022

discord.py ffmpeg song plays too quickly at the beginning

I build a discord bot using discord.py and ffmpeg, it works but the song in the first 0-5 seconds plays too fast, I think it's buffering so I tried to use asyncio.sleep but didn't work, suggestions to solve the problem?

play func:

with youtube_dl.YoutubeDL(self.opts) as ydl:
    await asyncio.sleep(0.1)
    ydl.cache.remove()
    await asyncio.sleep(0.1)
    info = ydl.extract_info(url, download=False)
    raw_url_song = info['formats'][0]['url']
    await self.real_play(ctx, raw_url_song)

real_play func:

source = await discord.FFmpegOpusAudio.from_probe(processed_url_song, **self.FFMPEG_OPTIONS)
await asyncio.sleep(0.5)
self.vc.play(source, after=lambda e: asyncio.run_coroutine_threadsafe(self.real_play(ctx, processed_url_song), self.client.loop))

these are the options:

self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
self.OPTIONS = {'format': 'bestaudio'}
self.opts = {'extract_flat': True, 'skip_download': True}

the functions are separate because I do something else (such as playlists), I have reported only the essential code to understand the problem, and the cache remove is essential to reduce the occurence of HTTP 404 forbidden error, btw also without cache remove the problem persists



from discord.py ffmpeg song plays too quickly at the beginning

No comments:

Post a Comment