简体   繁体   中英

Using ffmpeg on PythonAnywhere

My (first) web app uses pydub, which depends on ffmpeg. On my local windows environment, I installed ffmpeg and added the path to the ffmpeg executables to the windows "path" environment variables.

It all works locally, but bow that I have deployed my app to PythonAnywhere, the following line in my code is causing an error:

 sound.export(export_path, format="mp3", bitrate="128k")

I believe the error is because this code relies on ffmpeg.

I have read on their forums that ffmpeg is installed for all users on PythonAnywhere. Is there something I need to do to get it to work? Do I need to add the path of the ffmpeg files to the environment variables? I have a.env file with other env variables -- would I need to add something to this?

Got home and tried PythonAnywhere myself, and I don't find any issue with it and its FFmpeg.

Without installing anything (no FFmpeg, no Python packages), I run successfully in REPL:

>>> os.system('ffmpeg')
[snipped ffmpeg banner]
>>> import pydub
>>> pydub.utils.get_encoder_name()
'ffmpeg'
>>> pydub.utils.get_prober_name()
'ffprobe'
>>> pydub.utils.get_supported_codecs()
[snipped a large list of FFmpeg codecs]

So, your issue is not ffmpeg/pydub. Post the exact error. Can it be that it doesn't like you to save a file in the directory you specified?

The problem was not ffmpeg - which I have confirmed is installed for all users on PythonAnywhere. Instead, my issue was the export path I was using with pydub. I fixed my issue by changing:

export_path = "media/my_path"

to

export_path = "home/my_app/my_app/media/my_path"

which is then used in

sound.export(export_path, format="mp3", bitrate="128k")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM