FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

我是 python 的新手,我正在使用 pydub 模块来播放 mp3 曲目。

这是我播放 mp3 的简单代码:

#Let's play some mp3 files using python!

from pydub import AudioSegment
from pydub.playback import play

song = AudioSegment.from_mp3("/media/rajendra/0C86E11786E10256/05_I_Like_It_Rough.mp3")
play(song)

当我运行这个程序时,它说:

*/usr/bin/python3.4 /home/rajendra/PycharmProjects/pythonProject5/myProgram.py
/usr/local/lib/python3.4/dist-packages/pydub/utils.py:161: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
  warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
/usr/local/lib/python3.4/dist-packages/pydub/utils.py:174: RuntimeWarning: Couldn't find ffplay or avplay - defaulting to ffplay, but may not work
  warn("Couldn't find ffplay or avplay - defaulting to ffplay, but may not work", RuntimeWarning)
Traceback (most recent call last):
  File "/home/rajendra/PycharmProjects/pythonProject5/myProgram.py", line 11, in <module>
    song = AudioSegment.from_mp3("/media/rajendra/0C86E11786E10256/05_I_Like_It_Rough.mp3")
  File "/usr/local/lib/python3.4/dist-packages/pydub/audio_segment.py", line 355, in from_mp3
    return cls.from_file(file, 'mp3')
  File "/usr/local/lib/python3.4/dist-packages/pydub/audio_segment.py", line 339, in from_file
    retcode = subprocess.call(convertion_command, stderr=open(os.devnull))
  File "/usr/lib/python3.4/subprocess.py", line 533, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.4/subprocess.py", line 848, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.4/subprocess.py", line 1446, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

Process finished with exit code 1*

请帮帮我!我检查了所有路径,但它不起作用。我目前正在使用 Ubuntu。

不胜感激!

就像警告说的那样:

Couldn't find ffplay or avplay - defaulting to ffplay, but may not work

您需要 ffplayavplay;但是 ffplay 指的是 ffmpeg,它在最近版本的 Ubuntu 中是不可安装的。使用 apt-get:

安装 libav-tools
sudo apt-get install libav-tools

看来您需要 ffmpeg,但是

sudo apt-get install ffmpeg 

不再有效。您可以通过以下方式获取 ffmpeg:

sudo add-apt-repository ppa:jon-severinsson/ffmpeg
sudo apt-get update
sudo apt-get install ffmpeg

如果它不允许您使用 sudo apt-get install libav-tools 安装,您可以 download the .deb from here:

wget http://launchpadlibrarian.net/339874908/libav-tools_3.3.4-2_all.deb

然后运行sudo apt install ./libav-tools_3.3.4.2_all.deb

sudo apt-get install ffmpeg

注:测试于 Ubuntu 18.04

我在 Ubuntu Ubuntu 18.04.3 LTS 上遇到了同样的问题。

只需安装 ffmpeg 即可解决此问题:

sudo apt-get install ffmpeg 

而不是流行的 Git-thread (https://github.com/lengstrom/fast-style-transfer/issues/129) 建议:

brew install ffmpeg

但如果一个不起作用,您可以随时尝试两者。