
Recherche avancée
Autres articles (40)
-
Taille des images et des logos définissables
9 février 2011, parDans beaucoup d’endroits du site, logos et images sont redimensionnées pour correspondre aux emplacements définis par les thèmes. L’ensemble des ces tailles pouvant changer d’un thème à un autre peuvent être définies directement dans le thème et éviter ainsi à l’utilisateur de devoir les configurer manuellement après avoir changé l’apparence de son site.
Ces tailles d’images sont également disponibles dans la configuration spécifique de MediaSPIP Core. La taille maximale du logo du site en pixels, on permet (...) -
Configuration spécifique d’Apache
4 février 2011, parModules spécifiques
Pour la configuration d’Apache, il est conseillé d’activer certains modules non spécifiques à MediaSPIP, mais permettant d’améliorer les performances : mod_deflate et mod_headers pour compresser automatiquement via Apache les pages. Cf ce tutoriel ; mode_expires pour gérer correctement l’expiration des hits. Cf ce tutoriel ;
Il est également conseillé d’ajouter la prise en charge par apache du mime-type pour les fichiers WebM comme indiqué dans ce tutoriel.
Création d’un (...) -
Encodage et transformation en formats lisibles sur Internet
10 avril 2011MediaSPIP transforme et ré-encode les documents mis en ligne afin de les rendre lisibles sur Internet et automatiquement utilisables sans intervention du créateur de contenu.
Les vidéos sont automatiquement encodées dans les formats supportés par HTML5 : MP4, Ogv et WebM. La version "MP4" est également utilisée pour le lecteur flash de secours nécessaire aux anciens navigateurs.
Les documents audios sont également ré-encodés dans les deux formats utilisables par HTML5 :MP3 et Ogg. La version "MP3" (...)
Sur d’autres sites (3946)
-
Making my Discord Bot automatically play music from WAV on loop
5 décembre 2022, par Mativ9So I was trying to make a Discord Bot in Python, which would atomatically join a voice channel and play my own music from a list in a loop. So far it's joining the channel, shuffling the list so the music is on random, but when I try to write a code so after one song it will play the next one it crushes and doesn't play anything (tho it's joining the channel)


import discord
import random
from discord.ext import commands
from discord import FFmpegPCMAudio

#playlist as a list
queue = [FFmpegPCMAudio('Iceland1.wav'), FFmpegPCMAudio('Iceland2.wav'), FFmpegPCMAudio('Iceland3.wav'), FFmpegPCMAudio('Iceland4.wav'),
 FFmpegPCMAudio('Iceland5.wav'), FFmpegPCMAudio('Iceland6.wav'), FFmpegPCMAudio('Iceland7.wav'), FFmpegPCMAudio('Iceland8.wav'),
 FFmpegPCMAudio('Iceland9.wav'), FFmpegPCMAudio('Iceland10.wav'), FFmpegPCMAudio('Norway1.wav'), FFmpegPCMAudio('Norway2.wav'),
 FFmpegPCMAudio('Norway3.wav'), FFmpegPCMAudio('Norway4.wav'), FFmpegPCMAudio('Norway5.wav'), FFmpegPCMAudio('Norway6.wav'),
 FFmpegPCMAudio('Norway7.wav'), FFmpegPCMAudio('Norway8.wav'), FFmpegPCMAudio('Norway9.wav'), FFmpegPCMAudio('Norway10.wav'),
 FFmpegPCMAudio('Norway11.wav'), FFmpegPCMAudio('Presents1.wav'), FFmpegPCMAudio('Presents2.wav'), FFmpegPCMAudio('Presents3.wav'),
 FFmpegPCMAudio('Presents4.wav'), FFmpegPCMAudio('Presents5.wav'), FFmpegPCMAudio('Presents6.wav'), FFmpegPCMAudio('Presents7.wav'),
 FFmpegPCMAudio('Presents8.wav'), FFmpegPCMAudio('Presents9.wav'), FFmpegPCMAudio('Presents10.wav'), FFmpegPCMAudio('Autumn1.wav'),
 FFmpegPCMAudio('Autumn2.wav'), FFmpegPCMAudio('Autumn3.wav'), FFmpegPCMAudio('Autumn4.wav'), FFmpegPCMAudio('Autumn5.wav'),
 FFmpegPCMAudio('Autumn6.wav'), FFmpegPCMAudio('Autumn7.wav'), FFmpegPCMAudio('Autumn8.wav'), FFmpegPCMAudio('Covers1.wav'),
 FFmpegPCMAudio('Covers2.wav'), FFmpegPCMAudio('Covers3.wav'), FFmpegPCMAudio('Covers4.wav'), FFmpegPCMAudio('Covers5.wav'),
 FFmpegPCMAudio('Covers6.wav'), FFmpegPCMAudio('Covers7.wav'), FFmpegPCMAudio('Covers8.wav'), FFmpegPCMAudio('Covers9.wav'),
 FFmpegPCMAudio('Covers10.wav'), FFmpegPCMAudio('Covers11.wav'), FFmpegPCMAudio('Covers12.wav')]

intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix='>', intents=intents)

@client.event
async def on_ready():
 global voice
 print("The Matt Bot is ready")
 print("--------------------------")
 await client.change_presence(activity=discord.Game('Matt Krupa')) #makes my bot play Matt Krupa
 channel = client.get_channel(thechannelid) #geting channel ID
 voice = await channel.connect() #connecting to channel
 random.shuffle(queue) #randomazing the playlist
 def after_song(): #moving the first song to the end so its on loop, and playling the next one
 queue.append(queue[0])
 del queue[0]
 player = await voice.play(queue[0], after=await after_song())
 player = await voice.play(queue[0], after=await after_song()) #plays song from the playlist, after the song doing the after_song() function

client.run(mytokenidontwanttoshowitsry)



I wanted it to play all the songs on the infinite loop, i can't find how to correctly detect the end of a song...


-
discord.py music bot slowing down for longer audio queries
1er janvier 2023, par BoblugeSo I'm trying to make a music bot with discord.py. Shown below is a minimum working example of the bot with the problematic functions :


import os

import discord
from discord.ext import commands
from discord import player as p

import yt_dlp as youtube_dl

intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(command_prefix=';')

class Music(commands.Cog):
 def __init__(self, bot):
 self.bot = bot
 self.yt-dlp_opts = {
 'format': 'bestaudio/best',
 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
 'restrictfilenames': True,
 'noplaylist': True,
 'playlistend': 1,
 'nocheckcertificate': True,
 'ignoreerrors': False,
 'logtostderr': False,
 'quiet': True,
 'no_warnings': True,
 'default_search': 'auto',
 'source_address': '0.0.0.0', # bind to ipv4 since ipv6 addresses cause issues sometimes
 }
 self.ffmpeg_opts = {
 'options': '-vn',
 # Source: https://stackoverflow.com/questions/66070749/
 "before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5",
 }
 self.cur_stream = None
 self.cur_link = None

 @commands.command(aliases=["p"])
 async def play(self, ctx, url):
 yt-dlp = youtube_dl.YoutubeDL(self.ytdl_opts)
 data = yt-dlp.extract_info(url, download=False)
 filename = data['url'] # So far only works with links
 print(filename)
 audio = p.FFmpegPCMAudio(filename, **self.ffmpeg_opts)
 self.cur_stream = audio
 self.cur_link = filename

 # You must be connected to a voice channel first
 await ctx.author.voice.channel.connect()
 ctx.voice_client.play(audio)
 await ctx.send(f"now playing")

 @commands.command(aliases=["ff"])
 async def seek(self, ctx):
 """
 Fast forwards 10 seconds
 """
 ctx.voice_client.pause()
 for _ in range(500):
 self.cur_stream.read() # 500*20ms of audio = 10000ms = 10s
 ctx.voice_client.resume()

 await ctx.send(f"fast forwarded 10 seconds")

 @commands.command(aliases=["j"])
 async def jump(self, ctx, time):
 """
 Jumps to a time in the song, input in the format of HH:MM:SS
 """
 ctx.voice_client.stop()
 temp_ffempg = {
 'options': '-vn',
 # Keyframe skipping when passed as an input option (fast)
 "before_options": f"-ss {time} -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5",
 }
 new_audio = p.FFmpegPCMAudio(self.cur_link, **temp_ffempg)
 self.cur_stream = new_audio
 ctx.voice_client.play(new_audio)
 await ctx.send(f"skipped to {time}")


bot.add_cog(Music(bot))
bot.run(os.environ["BOT_TOKEN"])



My
requirements.txt
file :

discord.py[voice]==1.7.3
yt-dlp==2021.9.2



To play a song in Discord the following format is used :


;p 



Where
is any link that yt-dlp supports. Under normal circumstances, the
;p
command is used with songs that are relatively short, to whichseek()
andjump()
work extremely quickly to do what they are supposed to do. For example if I execute these sequence of commands in Discord :

;p https://www.youtube.com/watch?v=n8X9_MgEdCg <- 4 min song



And when the bot starts playing, spam the following :


;ff
;ff
;ff
;ff
;ff



The bot is able to almost instantly seek five 10-second increments of the song. Additionally, I can jump to the three minute mark very quickly with :


;j 00:03:00



From some experimentation, the
seek()
andjump()
functions seem to work quickly for songs that are under 10 minutes. If I try the exact same sequence of commands but with a 15 minute song likehttps://www.youtube.com/watch?v=Ks9Ck5LfGWE
or longerhttps://www.youtube.com/watch?v=VThrx5MRJXA
(10 hours classical music), there is an evident slowdown when running the;ff
command. However, when I include a few seconds of delay between firings of the;ff
command, the seeking is just as fast as previously mentioned. I'm not exactly sure what is going on with yt-dlp/FFmpeg behind the scenes when streaming, but I speculate that there is some sort of internal buffer, and songs that pass a certain length threshold are processed differently.

For longer songs, the
seek()
command takes longer to get to the desired position, which makes sense since this site specifies that-ss
used as an input option loops through keyframes (as there must be more keyframes in longer songs). However, if the following commands are run in Discord :

;p https://www.youtube.com/watch?v=VThrx5MRJXA <- 10 hour classical music
;j 09:00:00 <- jump to 9 hour mark
;j 00:03:00 <- jump to 3 minute mark



The first seek command takes around 5 to 10 seconds to perform a successful seek, which isn't bad, but it could be better. The second seek command takes around the same time as the first command, which doesn't make sense to me, because I thought less keyframes were skipped in order to reach the 3 minute mark.


So I'm wondering what's going on, and how to potentially solve the following :


- 

- What is actually going on with the
seek()
command ? My implementation ofseek()
uses discord.py'sdiscord.player.FFmpegPCMAudio.read()
method, which apparently runs slower if the song's length is longer ? Why ? - Why does input seeking for long YouTube videos take almost the same time no matter where I seek to ?
- How the yt-dlp and FFmpeg commands work behind the scenes to stream a video from YouTube (or any other website that YTDL supports). Does yt-dlp and FFmpeg behave differently for audio streams above a certain length threshold ?
- Potential ways to speed up
seek()
andjump()
for long songs. I recall some well-known discord music bots were able to do this very quickly.










- What is actually going on with the
-
Python Discord music bot stops playing a couple of minutes into any song
9 mars 2023, par knewbyI am trying to put together a Python Discord music bot as a fun little project. Outside of the required discord library I'm currently using the YouTube API to search for videos and parse the URL (not shown in code), yt-dlp which is a fork of yt_download that is still maintained to get the info from the YT URL, and FFMPEG to play the song obtained from yt-dlp through the bot. My play command seems to work as the 1st YT video result will start to play, but roughly 30-90 seconds into the audio, it stops playing. I get this message in the console :


2023-02-23 14:54:44 IN discord.player ffmpeg process 4848 successfully terminated with return code of 0.


So there is no error for me to go off of. I've included the full output from the console below...


-----------------------------------
groovy-jr#6741 is up and running
-----------------------------------
2023-02-23 14:53:23 INFO discord.voice_client Connecting to voice...
2023-02-23 14:53:23 INFO discord.voice_client Starting voice handshake... (connection attempt 1)
2023-02-23 14:53:24 INFO discord.voice_client Voice handshake complete. Endpoint found us-south1655.discord.media
2023-02-23 14:54:44 INFO discord.player ffmpeg process 4848 successfully terminated with return code of 0. <= AUDIO STOPS



I'm currently developing this project on a Windows 11 machine, but I've had the issue running it on my Ubuntu machine as well. I am just hosting the bot directly from the VSCode terminal for development.


I've been trying to do research on this problem, the problem is I can't find many recent information for the issue. There was another post that talked about a similar problem and had an answer suggesting the following FFMPEG options be used which I tried to no avail.


FFMPEG_OPTIONS = {
 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
 'options': '-vn',
 }



I'll include the problem file below :


import discord
from discord.ext import commands
from discord import FFmpegPCMAudio
import responses
import youtubeSearch as YT
import yt_dlp

async def send_message(message, user_message, is_private = False):
 try:
 response = responses.handle_response(user_message)
 await message.author.send(response) if is_private else await message.channel.send(response)
 except Exception as e:
 print(e)

def run_discord_bot():
 intents = discord.Intents.default()
 intents.message_content = True

 TOKEN = 'xxxxxx'
 client = commands.Bot(command_prefix = '-', intents=intents)

 @client.event
 async def on_ready():
 print('-----------------------------------')
 print(f'{client.user} is up and running')
 print('-----------------------------------')

 @client.command(name='play', aliases=['p'], pass_context = True)
 async def play(ctx, *, search_term:str = None):
 if ctx.author.voice:
 voice = None
 if search_term == None:
 await ctx.send('No song specified.')
 return
 if not ctx.voice_client:
 channel = ctx.message.author.voice.channel
 voice = await channel.connect()
 else:
 voice = ctx.guild.voice_client
 
 url = YT.singleSearch(search_term)
 
 YTDLP_OPTIONS = {
 'format': 'bestaudio/best',
 'extractaudio': True,
 'audioformat': 'mp3',
 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
 'restrictfilenames': True,
 'noplaylist': True,
 'nocheckcertificate': True,
 'ignoreerrors': False,
 'logtostderr': False,
 'quiet': True,
 'no_warnings': True,
 'default_search': 'ytsearch',
 'source_address': '0.0.0.0',
 }

 =====> FFMPEG_OPTIONS = {
 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
 'options': '-vn',
 }

 with yt_dlp.YoutubeDL(YTDLP_OPTIONS) as ydl:
 info = ydl.extract_info(url, download=False)
 playUrl = info['url']

 source = FFmpegPCMAudio(playUrl, options=FFMPEG_OPTIONS)
 voice.play(source)
 else:
 await ctx.send('You must be in a voice channel to play a song!')
 return

 @client.command(pass_context = True)
 async def leave(ctx):
 if ctx.voice_client:
 await ctx.guild.voice_client.disconnect()
 else:
 await ctx.send("I'm not in a voice channel!")

 @client.command(pass_context = True)
 async def pause(ctx):
 voice = discord.utils.get(client.voice_clients, guild = ctx.guild)
 if voice.is_playing():
 voice.pause()
 else:
 await ctx.send('No audio playing...')

 @client.command(pass_context = True)
 async def resume(ctx):
 voice = discord.utils.get(client.voice_clients, guild = ctx.guild)
 if voice.is_paused():
 voice.resume()
 else:
 await ctx.send('No audio paused...')

 @client.command(pass_context = True)
 async def stop(ctx):
 voice = discord.utils.get(client.voice_clients, guild = ctx.guild)
 voice.stop()

 client.run(TOKEN)



I appreciate any guidance I can get !