Heroku FFMPEG 后处理错误与 yt-dlp DownloadError
Heroku FFMPEG Postprocessing error with yt-dlp DownloadError
我正在构建一个使用 FFMPEG 下载和播放音乐的 discord 音乐机器人。 yt-dlp 似乎由于某种原因无法找到 ffmpeg 文件,尽管我给了它直接路径。当我 运行 它在我的 cpu 上时,它工作得很好,但它在 heroku 中不起作用。
这是 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
这是我的设置:
![根级目录]: https://i.stack.imgur.com/HKo8L.png
代码如下:
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"]}'])
你不能这样做:
'ffmpeg_location': './FFMPEG_CONFIG/ffmpeg.exe',
ffmpeg.exe
是一个 Windows 二进制文件。它不能在 Heroku 上使用(并且不应该是你的存储库的一部分)。
大多数想在 Heroku 上使用 ffmpeg
的用户使用 the buildpack (see also multiple buildpacks),例如:
heroku buildpacks:set heroku/python
heroku buildpacks:add --index 1 https://github.com/FFmpeg/FFmpeg.git
然后删除 hard-coded ffmpeg_location
、提交并重新部署。您的应用应该找到 ffmpeg
.
对于本地开发,您有两种选择:
- 更新您的
PATH
以确保可以找到 ffmpeg.exe
- 更新代码以设置
ffmpeg_location
,最好从环境变量
我正在构建一个使用 FFMPEG 下载和播放音乐的 discord 音乐机器人。 yt-dlp 似乎由于某种原因无法找到 ffmpeg 文件,尽管我给了它直接路径。当我 运行 它在我的 cpu 上时,它工作得很好,但它在 heroku 中不起作用。
这是 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
这是我的设置: ![根级目录]: https://i.stack.imgur.com/HKo8L.png
代码如下:
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"]}'])
你不能这样做:
'ffmpeg_location': './FFMPEG_CONFIG/ffmpeg.exe',
ffmpeg.exe
是一个 Windows 二进制文件。它不能在 Heroku 上使用(并且不应该是你的存储库的一部分)。
大多数想在 Heroku 上使用 ffmpeg
的用户使用 the buildpack (see also multiple buildpacks),例如:
heroku buildpacks:set heroku/python
heroku buildpacks:add --index 1 https://github.com/FFmpeg/FFmpeg.git
然后删除 hard-coded ffmpeg_location
、提交并重新部署。您的应用应该找到 ffmpeg
.
对于本地开发,您有两种选择:
- 更新您的
PATH
以确保可以找到ffmpeg.exe
- 更新代码以设置
ffmpeg_location
,最好从环境变量