Search code examples
pythonffmpegenvironment-variablespythonanywherepydub

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?


Solution

  • 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?