How to Solve "AttributeError: module 'ffmpeg' has no attribute 'input'" in Python
The error AttributeError: module 'ffmpeg' has no attribute 'input'
in Python typically occurs when you've installed the wrong ffmpeg
package. The correct package for interacting with FFmpeg in Python is ffmpeg-python
, not ffmpeg
or python-ffmpeg
.
This guide explains the correct installation process and troubleshooting steps.
Understanding the Error: Incorrect Package
The error message AttributeError: module 'ffmpeg' has no attribute 'input'
clearly indicates that the ffmpeg
module you've imported doesn't have the expected input
function.
This happens because the ffmpeg
package on PyPI is not the correct package for programmatic control of FFmpeg. You need ffmpeg-python
. Similarly, python-ffmpeg
is also incorrect.
Installing the Correct Package: ffmpeg-python
Uninstalling Incorrect Packages**
First, uninstall any conflicting packages:
pip uninstall ffmpeg python-ffmpeg ffmpeg-python # Remove any existing, potentially clashing packages
pip3 uninstall ffmpeg python-ffmpeg ffmpeg-python # Use pip3 if needed
python -m pip uninstall ffmpeg python-ffmpeg ffmpeg-python # If pip is not found, use python -m pip
python3 -m pip uninstall ffmpeg python-ffmpeg ffmpeg-python # If pip3 is not found, use python3 -m pip
- It's critical to remove all potentially conflicting packages.
Installing ffmpeg-python
Now, install the correct ffmpeg-python
package:
pip install ffmpeg-python
# OR, for Python 3 (might be pip3, pip3.10, etc. on your system)
pip3 install ffmpeg-python
# OR, if pip is not in your PATH
python -m pip install ffmpeg-python
python3 -m pip install ffmpeg-python
# OR, for Anaconda
conda install -c conda-forge ffmpeg-python
# OR, in a Jupyter Notebook
!pip install ffmpeg-python
If you encounter permission errors, try:
sudo pip3 install ffmpeg-python # On macOS/Linux (use with caution!)
pip install ffmpeg-python --user # Installs for the current user only
Verifying the Installation
After installing, verify that you have the correct package and can access the input
function:
import ffmpeg
print(dir(ffmpeg)) # Should show 'input' in the output
print(ffmpeg.__file__) # Should show a path ending in .../site-packages/ffmpeg/__init__.py
- Check that
input
is listed in the output ofdir(ffmpeg)
. - Also print the path to the file to make sure that the correct
ffmpeg
module is being used.
Verifying FFmpeg Installation (Crucial!)
ffmpeg-python
is a wrapper around the FFmpeg command-line tool. You must have FFmpeg itself installed separately on your system.
This is the most common reason why ffmpeg-python
code still fails even after correct package installation.
-
Windows: Download a pre-built executable from a reputable source (like https://www.gyan.dev/ffmpeg/builds/) and add the directory containing
ffmpeg.exe
to your system'sPATH
environment variable. Do not just placeffmpeg.exe
in your project directory; it needs to be in a location where your system can find it. -
macOS: Use Homebrew:
brew install ffmpeg
-
Linux: Use your distribution's package manager (e.g.,
apt install ffmpeg
on Debian/Ubuntu,yum install ffmpeg
on CentOS/Fedora).
To verify FFmpeg is installed and in your PATH
, open a new terminal/command prompt window (important, so it picks up any PATH changes) and run:
ffmpeg -version
You should see output showing the FFmpeg version and build information. If you get a "command not found" error, FFmpeg is not installed correctly or not in your PATH
.
Checking for Naming Conflicts
Ensure you don't have a file named ffmpeg.py
in your project directory. This will shadow the installed ffmpeg-python
module and cause the AttributeError
. Rename your file if it exists.
import ffmpeg
print(dir(ffmpeg)) # Check the output to ensure it's the correct module.
print(ffmpeg.__file__) # Verify the file location (should be in site-packages)
Conclusion
The AttributeError: module 'ffmpeg' has no attribute 'input'
error is almost always due to installing the wrong ffmpeg
package.
By uninstalling incorrect packages, installing ffmpeg-python
, verifying the FFmpeg installation, and checking for naming conflicts, you can resolve this error and use the ffmpeg-python
library correctly.
Remember that ffmpeg-python
requires a separate FFmpeg installation on your system.
If, after following all these steps, you still have problems, double-check your FFmpeg installation and your system's PATH
environment variable. If you're in a virtual environment, make sure FFmpeg is accessible within that environment.