ffmpeg未找到。我该如何解决?

6

我正在尝试制作一个简单的Discord音乐机器人,但目前由于这个问题而停滞不前。问题在于,每次我尝试通过youtube_dl库播放音乐时,它会弹出提示:“未找到ffmpeg”。

这是main.py文件:


import discord
import os
import asyncio
import youtube_dl
import ffmpeg

token = 'NzY5NTUzNDcwNjAwMTE4Mjgz.G3Dzce.XYKNAyLfBPg0ug5XPKssV-9EvsFjBlCMeM43ag'

client = discord.Client()

block_words = ['dick', 'nigga', 'ujku shijakut', 'arli', 'http://', 'https://']

voice_clients = {}
yt_dl_opts = {'format': 'bestaudio/best'}
ytdl = youtube_dl.YoutubeDL(yt_dl_opts)

ffmpeg_options = {'options': '-vn'}


@client.event
async def on_ready():
    print(f'Bot has logged in as {client.user}')

@client.event
async def on_message(msg):
    if msg.author != client.user:
        if msg.content.lower().startswith('?hi'):
            await msg.channel.send(f'Hi, {msg.author.display_name}')

@client.event
async def on_message(msg):
    if msg.author != client.user:
        for text in block_words:
            if "OTR" not in str(msg.author.roles) and text in str(msg.content.lower()):
                await msg.delete()
                return
        print("Not Deleting...")

@client.event
async def on_message(msg):
    if msg.content.startswith('?play'):
        try:
            url = msg.content.split()[1]

            voice_client = await msg.author.voice.channel.connect()
            voice_clients[voice_client.guild.id] = voice_client

            loop = asyncio.get_event_loop()
            data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))

            song = data['url']
            player = discord.FFmpegPCMAudio(song, **ffmpeg_options)
        except Exception as err:
            print(err)
client.run(token)


FFmpeg是一个工具,如果你正在运行Linux,很有可能你可以使用软件包管理器来安装它。这应该可以解决你的问题。例如:apt install ffmpeg - W00dy
1
如果您正在运行Windows操作系统,您需要从https://ffmpeg.org/download.html#build-windows下载FFMPEG可执行文件,并将其放置在脚本的工作目录中。 - Parasol Kirby
你泄漏了你的令牌,请立即重置。 - Eric Jin
没问题,Eric。毕竟这是一个测试机器人。 - Ice Cr3aM
1个回答

4

FFMPEG是一款音视频处理工具,错误提示ffmpeg was not found意味着您未安装FFMPEG。

如果您使用的操作系统为Linux,则可以使用命令sudo apt install ffmpeg安装。

如果您使用的操作系统为Windows,可以从官方下载页面下载FFMPEG:https://ffmpeg.org/download.html#build-windows

如果您使用的操作系统为MacOS,也可以从官方下载页面下载:https://ffmpeg.org/download.html#build-mac

请注意,如果您从网站下载可执行文件,您需要手动将其移到脚本目录(或将其添加到PATH)中。

此错误与Youtube无关。 Youtube不能阻止您下载视频,也不能阻止您使用视频处理工具。


你的意思是将下载的ffmpeg文件夹添加到应用程序中吗?具体放在哪里? - nour
@nour 你需要将它添加到程序的工作目录中。如果你正在使用 PyCharm 或其他IDE,那么它可能是你正在运行脚本的目录。如果你正在使用命令提示符,则它是命令提示符的工作目录(即你输入 cd 命令进入的目录,或者在命令前显示的路径)。 - Parasol Kirby

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接