FileNotFoundError:[Errno 2]没有这样的文件或目录:“ffmpeg”

2024-04-19 05:15:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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。

希望您能帮忙!


Tags: orinfrompylibpackagesusrlocal
3条回答

就像警告说的:

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
sudo apt-get install ffmpeg

注意:在Ubuntu 18.04上测试

看起来你需要ffmpeg,但是

sudo apt-get install ffmpeg 

不再工作了。您可以通过以下方式获取ffmpeg:

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

相关问题 更多 >