Home > database >  Heroku FFMPEG Postprocessing error with yt-dlp DownloadError
Heroku FFMPEG Postprocessing error with yt-dlp DownloadError

Time:02-15

I am building a discord music bot that uses FFMPEG to download and play the music. yt-dlp seems to not be able to find the ffmpeg file for some reason although I give it the direct path. It works perfectly fine whe I run it on my cpu, but it doesn't work in heroku.

Here's the error in heroku:

2022-02-14T00:34:29.047823 00:00 app[worker.1]: During handling of the above exception, another exception occurred:
2022-02-14T00:34:29.047823 00:00 app[worker.1]: 
2022-02-14T00:34:29.047825 00:00 app[worker.1]: Traceback (most recent call last):
2022-02-14T00:34:29.047854 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
2022-02-14T00:34:29.047855 00:00 app[worker.1]:     await coro(*args, **kwargs)
2022-02-14T00:34:29.047856 00:00 app[worker.1]:   File "/app/engine.py", line 97, in on_reaction_add
2022-02-14T00:34:29.047856 00:00 app[worker.1]:     ydl.download([f'{result["link"]}'])
2022-02-14T00:34:29.047863 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 3212, in download
2022-02-14T00:34:29.047863 00:00 app[worker.1]:     self.__download_wrapper(self.extract_info)(
2022-02-14T00:34:29.047865 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 3185, in wrapper
2022-02-14T00:34:29.047865 00:00 app[worker.1]:     res = func(*args, **kwargs)
2022-02-14T00:34:29.047875 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1372, in extract_info
2022-02-14T00:34:29.047876 00:00 app[worker.1]:     return self.__extract_info(url, self.get_info_extractor(ie_key), download, extra_info, process)
2022-02-14T00:34:29.047877 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1381, in wrapper
2022-02-14T00:34:29.047877 00:00 app[worker.1]:     return func(self, *args, **kwargs)
2022-02-14T00:34:29.047891 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1465, in __extract_info
2022-02-14T00:34:29.047891 00:00 app[worker.1]:     return self.process_ie_result(ie_result, download, extra_info)
2022-02-14T00:34:29.047893 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 1517, in process_ie_result
2022-02-14T00:34:29.047894 00:00 app[worker.1]:     ie_result = self.process_video_result(ie_result, download=download)
2022-02-14T00:34:29.047894 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 2607, in process_video_result
2022-02-14T00:34:29.047894 00:00 app[worker.1]:     self.process_info(new_info)
2022-02-14T00:34:29.047896 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 3161, in process_info
2022-02-14T00:34:29.047896 00:00 app[worker.1]:     self.report_error('Postprocessing: %s' % str(err))
2022-02-14T00:34:29.047904 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 930, in report_error
2022-02-14T00:34:29.047904 00:00 app[worker.1]:     self.trouble(f'{self._format_err("ERROR:", self.Styles.ERROR)} {message}', *args, **kwargs)
2022-02-14T00:34:29.047905 00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/yt_dlp/YoutubeDL.py", line 871, in trouble
2022-02-14T00:34:29.047905 00:00 app[worker.1]:     raise DownloadError(message, exc_info)
2022-02-14T00:34:29.047921 00:00 app[worker.1]: yt_dlp.utils.DownloadError: ERROR: Postprocessing: ffprobe and ffmpeg not found. Please install or provide the path using --ffmpeg-location

Here's my setup: ![root level directory]: https://i.stack.imgur.com/HKo8L.png

Here's the code:

yt_opts = {
        'format': 'bestaudio/best',
        'ffmpeg_location': './FFMPEG_CONFIG/ffmpeg.exe',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }]
    }
# Getting Song From Thy YOUTUBE
     await channel.send("> Getting Song From Youtube")
     with yt_dlp.YoutubeDL(yt_opts) as ydl:
          ydl.download([f'{result["link"]}'])

CodePudding user response:

You can't do this:

'ffmpeg_location': './FFMPEG_CONFIG/ffmpeg.exe',

ffmpeg.exe is a Windows binary. It cannot be used on Heroku (and should not be part of your repository to begin with).

Most users who want to use ffmpeg on Heroku use the buildpack (see also multiple buildpacks), e.g.:

heroku buildpacks:set heroku/python
heroku buildpacks:add --index 1 https://github.com/FFmpeg/FFmpeg.git

Then remove that hard-coded ffmpeg_location, commit, and redeploy. Your app should find ffmpeg.

For local development you have a couple of of options:

  • Update your PATH to make sure ffmpeg.exe can be found
  • Update your code to set an ffmpeg_location, ideally from an environment variable
  • Related