'My discord.py music bot fails with "ffmpeg not found"

I am using repl.it to host my Discord.py music bot It fails with an error saying "ffmpeg is not found" I used multiple ways to fix the error

npm install ffmpeg-static in shell is my first way how i tried to fix the problem, but it did not do anything.

Even if i do any way, repl.it will still give the error ffmpeg not found. Can someone please tell any way to fix this issue??



Solution 1:[1]

ffmpeg-static npm package does not add ffmpeg to the system path. From documenatation:

Returns the path of a statically linked ffmpeg binary on the local filesystem.

    var pathToFfmpeg = require('ffmpeg-static');
    console.log(pathToFfmpeg);
    /Users/j/playground/node_modules/ffmpeg-static/ffmpeg

Your issue arises from Python runtime not having this path in its system path. So, you need to get that pathToFfmpeg value and use it in your discord.py call, e.g.,

discord.FFmpegAudio("input.wav", executable='/Users/j/playground/node_modules/ffmpeg-static/ffmpeg')

The other alternative is to add this /Users/j/playground/node_modules/ffmpeg-static to the (run-time) system path using

os.environ["PATH"] += os.pathsep + `/Users/j/playground/node_modules/ffmpeg-static`

There are alternates in Python, though. Namely, ffmpeg-static or ffmpeg-downloader package (I'm the owner of the latter). They achieve the same end-goal but behave a bit differently. Either should work for your use-case if you choose to go this route.

static-ffmpeg

This one downloads the binaries inside its Lib/site-packages folder, and the downloading occurs during the first execution within your python script/app. The binaries it downloads are hosted by the package owner.

pip install static-ffmpeg
from static_ffmpeg import run

ffmpeg, ffprobe = run.get_or_fetch_platform_executables_else_raise()
discord.FFmpegAudio("input.wav", executable=ffmpeg)

ffmpeg-downloader

This downloads to an external user folder (specified by appdirs package) and downloading is executed outside of python user script/app. It fetches the binaries directly from the hosts listed on FFmpeg website.

pip install ffmpeg-downloader
python -m ffmpeg_downloader
import ffmpeg_downloader as ffdl

discord.FFmpegAudio("input.wav", executable=ffdl.ffmpeg_path)

Solution 2:[2]

Something is wrong, It still shows FFMPEG is not found..

This is my code :

@commands.command()
async def play(self,ctx, url):
  
  FFMPEG_OPTIONS = {"before_options": "-reconnect 1-reconnect_streamed 1 -reconnect_delay_max 5","options":"-vn"}
  YDL_OPTIONS = {"format":"bestaudio"}
  vc = ctx.voice_client
  with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
    
    info = ydl.extract_info(url,download=False)
    url2 = info['formats'][0]['url']
    await ctx.send("Playing song")
    opusaudio = await discord.FFmpegOpusAudio.from_probe(url2,**FFMPEG_OPTIONS)
    source = discord.FFmpegAudio(opusaudio, executable='/Users/j/playground/node_modules/ffmpeg-static/ffmpeg')
    vc.play(source)

At all times, it shows "FFMPEG is not found" as an error. I searched online and for repls in repl.it but none of them seems to work for me. All it just shows is, "FFMPEG not found" Can someone please do help me with this error??

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kesh
Solution 2