AttributeError: module 'ffmpeg' has no attribute 'input'

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
3 min

banner

# AttributeError: module 'ffmpeg' has no attribute 'input'

The Python "AttributeError: module 'ffmpeg' has no attribute 'input'" occurs when you install the ffmpeg module instead of ffmpeg-python.

To solve the error, uninstall the ffmpeg module and install ffmpeg-python by running pip install ffmpeg-python.

attribute error module ffmpeg has no attribute input

The name of the module is ffmpeg-python, even though the import statement is import ffmpeg.

Open your terminal in your project's root directory and run the following commands to install the correct module.

  1. First, make sure to uninstall the ffmpeg module as it clashes with ffmpeg-python.
shell
pip uninstall ffmpeg pip3 uninstall ffmpeg python -m pip uninstall ffmpeg python3 -m pip uninstall ffmpeg

uninstall ffmpeg module

Also, make sure the python-ffmpeg module is not installed in the environment as it also clashes with the ffmpeg-python module.

shell
pip uninstall python-ffmpeg pip3 uninstall python-ffmpeg python -m pip uninstall python-ffmpeg python3 -m pip uninstall python-ffmpeg

pip uninstall python ffmpeg

You can verify that you don't have the ffmpeg and python-ffmpeg modules installed by running the following commands.

shell
pip show ffmpeg pip show python-ffmpeg # Or with pip3 pip3 show ffmpeg pip3 show python-ffmpeg

verify ffmpeg modules are not installed

Now, also uninstall the ffmpeg-python module to make sure it won't glitch due to clashing with ffmpeg or python-ffmpeg.

shell
pip uninstall ffmpeg-python pip3 uninstall ffmpeg-python python -m pip uninstall ffmpeg-python python3 -m pip uninstall ffmpeg-python

pip uninstall ffmpeg python

  1. Run one of the following commands to install the ffmpeg-python module.
shell
# ๐Ÿ‘‡๏ธ In a virtual environment or using Python 2 pip install ffmpeg-python # ๐Ÿ‘‡๏ธ For python 3 (could also be pip3.10 depending on your version) pip3 install ffmpeg-python

pip install ffmpeg python

If you get a permissions error, run the command prefixed with sudo (on macOS) or use the --user flag (all operating systems, outside a virtual environment).

shell
# ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip3 install ffmpeg-python pip install ffmpeg-python --user

If you don't have pip in your PATH environment variable, run the python -m pip install ffmpeg-python command.

shell
# ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install ffmpeg-python # ๐Ÿ‘‡๏ธ For python 3 (could also be pip3.10 depending on your version) python3 -m pip install ffmpeg-python

If you need to install ffmpeg-python using conda, use the following command instead.

shell
# ๐Ÿ‘‡๏ธ For Anaconda conda install -c conda-forge ffmpeg-python

If you need to install ffmpeg-python in Jupyter Notebook, prefix the pip command with an exclamation mark.

shell
# ๐Ÿ‘‡๏ธ For Jupyter Notebook !pip install ffmpeg-python

Once you install ffmpeg-python, you can import and use it as follows.

main.py
import ffmpeg stream = ffmpeg.input('input.mp4') stream = ffmpeg.hflip(stream) stream = ffmpeg.output(stream, 'output.mp4') ffmpeg.run(stream)

using ffmpeg python module

The code sample assumes that you have an input.mp4 file in the same location as your main.py script.

If the error persists, rerun the installation command with the --ignore-installed flag.

shell
pip install --ignore-installed ffmpeg-python pip3 install --ignore-installed ffmpeg-python # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install --ignore-installed ffmpeg-python python3 -m pip install --ignore-installed ffmpeg-python

install ffmpeg python with ignore installed

The --ignore-installed option ignores the installed packages and overwrites them.

# Make sure you don't have a file called ffmpeg.py

Make sure you don't have a local file called ffmpeg.py in your project.

Your local file will clash with the ffmpeg-python module and will shadow it.

If you have a local ffmpeg.py file, rename it to something else, e.g. my-ffmpeg.py.

Also, make sure to not name any variables ffmpeg as that would also clash with your import statement.

You can verify that you are importing the correct ffmpeg module by passing it to the dir() function.

main.py
import ffmpeg print(dir(ffmpeg))

pass ffmpeg module to dir function

Notice that the list of attributes contains the input method, therefore we are importing the correct ffmpeg module.

If you don't see the correct attributes in the list, then you are shadowing the ffmpeg module by having a local ffmpeg.py file.

You can also access the __file__ attribute on the imported module to get its location.

main.py
import ffmpeg # โœ… /home/borislav/Desktop/bobbyhadz_python/venv/lib/python3.10/site-packages/ffmpeg/__init__.py print(ffmpeg.__file__)

The module should be located in your site-packages directory.

If you instead, get a path similar to the following:

shell
/home/borislav/Desktop/bobbyhadz_python/ffmpeg.py

The you are likely shadowing the real ffmpeg-python module with a local ffmpeg.py file.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev