[Pydub] 读取mp3报错|Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work

代码:

# coding:utf8
from pydub import AudioSegment
hello = AudioSegment.from_file('hello.mp3',format = 'mp3')

报错:

C:\Python27\ArcGIS10.2\python2.exe E:/python/workspace/pydub/PyAudio.py
C:\Python27\ArcGIS10.2\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)
Traceback (most recent call last):
  File "E:/python/workspace/pydub/PyAudio.py", line 7, in 
    hello = AudioSegment.from_file('hello.mp3',format = 'mp3')
  File "C:\Python27\ArcGIS10.2\lib\site-packages\pydub\audio_segment.py", line 512, in from_file
    p = subprocess.Popen(conversion_command, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\Python27\ArcGIS10.2\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\ArcGIS10.2\lib\subprocess.py", line 896, in _execute_child
    startupinfo)
WindowsError: [Error 2]

问题:没有ffmpeg.exe

解决方案:

  1. 下载后放入工程目录下
  2. 使用代码引入ffmpeg.exe位置

    AudioSegment.converter = r"C:\\path\\to\\ffmpeg.exe"
    

你可能感兴趣的:(python)