subprocess.Popen仅在终端中工作

时间:2018-08-07 16:57:46

标签: python-3.x subprocess pydub

我正在尝试使用pydub.AudioSegment.from_mp3加载mp3文件,但是出现此错误

C:\ProgramData\Anaconda3\lib\site-packages\pydub\utils.py:165: 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)
my.mp3
C:\ProgramData\Anaconda3\lib\site-packages\pydub\utils.py:193: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
Traceback (most recent call last):
File "c:\Users\Max\Documents\Python\pydub_test.py", line 6, in <module>
    audio = AudioSegment.from_mp3(src)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydub\audio_segment.py", line 707, in from_mp3
    return cls.from_file(file, 'mp3', parameters)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydub\audio_segment.py", line 660, in from_file
    info = mediainfo_json(orig_file)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydub\utils.py", line 263, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

可以看到错误发生在子流程模块的某个地方。 但是当我在终端中尝试相同的操作时,

command = ['ffprobe', '-of', 'json', '-v', 'info', '-show_format', '-show_streams', 'my.mp3']
res = Popen(command, stdin=None, stdout=-1, stderr=-1)
res.communicate(input=None)

一切正常

此外,这是我的代码

from pydub import AudioSegment

# somehow pydub is not finding ffmepg even tough it is in my path
AudioSegment.converter = "C:/Program Files (x86)/ffmpeg-win64/bin/ffmpeg.exe"
AudioSegment.ffmpeg = "C:/Program Files (x86)/ffmpeg-win64/bin/ffmpeg.exe"
src = "my.mp3"
audio = AudioSegment.from_mp3(src)

0 个答案:

没有答案