5

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?

screenshot of Anaconda Navigator

alpha
  • 173
  • 1
  • 2
  • 12
  • I installed ffmpeg with `pip install python-ffmpeg` on Anaconda Prompt and now I can import it on Spyder. – alpha Aug 25 '21 at 21:47
  • `AttributeError: module 'ffmpeg' has no attribute 'input'` showed up, so I uninstalled `python-ffmpeg` and installed `ffmpeg-python` instead. – alpha Aug 25 '21 at 21:54

3 Answers3

8

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.

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
2

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")
Jon
  • 91
  • 1
  • 3
1

Try this to use pip command to install FFmpeg as a python library

pip install ffmpeg
fan276
  • 11
  • 1