ffmpeg is installed on Anaconda Navigator (in base(root)
environment), but when I run import ffmpeg
, I got this error message:
ModuleNotFoundError: No module named 'ffmpeg'
Why is this module not found and how can I fix this?
ffmpeg is installed on Anaconda Navigator (in base(root)
environment), but when I run import ffmpeg
, I got this error message:
ModuleNotFoundError: No module named 'ffmpeg'
Why is this module not found and how can I fix this?
You need to install the ffmpeg-python module to the environment:
pip install ffmpeg-python
or
conda install -c conda-forge ffmpeg-python
from there import ffmpeg
statements when using the environment should work.
I'm no expert but this thread on GitHub explains that anaconda installs FFmpeg as a script that can be run but not as a package you can import
. As such you need to note the path of the FFmpeg.exe for your anaconda environment + build the commands and pass them to the subprocess
module, which you do need to import. So, building on a SO questions like this one, to compress a video (for example), a Windows command in python might look something like:
import subprocess
pathFFmpeg = r'C:\Users\YOURNAME\anaconda3\envs\ENVNAME\Scripts\ffmpeg.exe'
pathInput = r'C:\Videos\mybigvideo.mp4'
pathOutput = r'C:\Videos\mysmallervideo.mp4'
commands_list = [
pathFFmpeg,
"-i", pathInput,
"-c:v", "libx265",
"-preset", "fast",
"-crf", "22",
"-c:a", "aac",
"-b:a", "196k",
"-pix_fmt", "yuv420p", pathOutput
]
results = subprocess.run(commands_list)
if results.returncode==0:
print ("FFmpeg Script Ran Successfully")
else:
print ("There was an error running your FFmpeg script")