gpt4 book ai didi

python - Heroku FFMPEG 后处理错误与 yt-dlp DownloadError

转载 作者:行者123 更新时间:2023-12-04 23:18:48 32 4
gpt4 key购买 nike

我正在构建一个使用 FFMPEG 下载和播放音乐的不和谐音乐机器人。 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
这是我的设置:
![根目录]: /image/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 上使用(并且不应该是你存储库的一部分)。
大多数想使用 ffmpeg的用户在 Heroku 上使用 the buildpack (另见 multiple buildpacks ),例如:
heroku buildpacks:set heroku/python
heroku buildpacks:add --index 1 https://github.com/FFmpeg/FFmpeg.git
然后删除硬编码 ffmpeg_location 、提交和重新部署。您的应用应该会找到 ffmpeg .
对于本地开发,您有两种选择:
  • 更新您的 PATH确保 ffmpeg.exe可以找到
  • 更新您的代码以设置 ffmpeg_location ,理想情况下来自环境变量
  • 关于python - Heroku FFMPEG 后处理错误与 yt-dlp DownloadError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71106114/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com