Reading in pydub AudioSegment from url. BytesIO returning “OSError [Errno 2] No such file or directory” on heroku only; fine on localhost

大憨熊 提交于 2019-12-06 15:55:22

All problems sorted, thanks

I can now read in AudioSegments from url using BytesIO. I can now export either mp3 or wav after processing.

ffmpeg issue was solved using the packs recommended here: http://blog.pogoapp.com/youtube-mp3-with-node-js-and-ffmpeg/ (replacing "nodejs" with my language, "python") The ffmpeg pack recommended there (https://github.com/jayzes/heroku-buildpack-ffmpeg) already includes the lame support I needed For some reason, https://github.com/integricho/heroku-buildpack-python-ffmpeg didn't quite do the job for me

I also had to add "ffprobe" into requirements.txt to allow youtube-dl to run properly (I mention that here since it was also previously complaining about lame missing... adding ffprobe was the second step to getting this to work)

Full writeup to my answer is here:https://github.com/rg3/youtube-dl/issues/302#issuecomment-60146845

Pydub uses ffmpeg to encode/decode all formats other than wav. So the first issue is getting ffmpeg installed on heroku.

You may find that using heroku run bash you can cd around and find the ffmpeg binary (try in /app/.heroku/vendor).

If that is the case you can explicitly specify where pydub should look like so:

import pydub


pydub.AudioSegment.converter = "/app/.heroku/vendor/ffmpeg/bin/ffmpeg" # or wherever you find it

edit

I was able to get the following to work:

create a requirements.txt in the root directory of an empty git repo.

requirements.txt:

pydub

add this and push to heroku.

the run:

heroku config:add BUILDPACK_URL=https://github.com/integricho/heroku-buildpack-python-ffmpeg.git

then:

heroku run bash

and in the shell

$ which ffmpeg
/app/.heroku/vendor/ffmpeg/bin/ffmpeg

$ python
>>> from pydub import AudioSegment
>>> AudioSegment.silent(5000).export("/tmp/asdf.mp3", "mp3")
<open file '/tmp/asdf.mp3', mode 'wb+' at 0x7ffa8aac0390>

after that ffmpeg is found at: /app/.heroku/vendor/ffmpeg/bin/ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!