使用pydub导出时出错 - 如何为pydub安装mp3编解码器? [英] Error when exporting with pydub - how to install mp3 codecs for pydub?

查看:750
本文介绍了使用pydub导出时出错 - 如何为pydub安装mp3编解码器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用这个库,所以我不知道这是一个错误,或者我没有正确地做某事。



我想导出一个文件到mp3,加载完美:

  wav = AudioSegment.from_wav(Path)#如果我只执行这一行,没有错误。 

但是当我尝试将我的文件导出到mp3时:

  wav.export(rWavOut.mp3,format =mp3)

它会引发以下错误:



WindowsError:[错误2]系统找不到指定的文件



完整错误报告: http://pastebin.com/3CpZBkEK



我相信我使用的是正确的语法。
它创建mp3输出文件但绝对是空的,输入路径是正确的,因为:

  os.startfile路径)#工作

另外,我在Windows路径中注册了ffmpeg:

 ; c:\ffmpeg\bin#目前可以从Windows中的任何cmd提示符调用。 

可能会失败?谢谢!






经过更多测试,我发现它的编码问题。如果我将输出设置为wav,它可以工作。但是我真的不知道如何安装一个mp3编码器来处理pydub,所以我改变了问题,因为它是真正的问题。 ffmpeg被安装,所以我不知道还有什么要做的:\

解决方案

我觉得找不到ffmpeg二进制文件。 Python内置了wave支持,所以pydub不需要ffmpeg来打开/关闭/修改wave文件。



在使用之前尝试分配ffmpeg二进制文件的位置如下所示:

 

ffmpeg.exe

wav = AudioSegment.from_wav(Path)#如果我只执行这一行,没有错误。
wav.export(rWavOut.mp3,format =mp3)

编辑:我们更改了将 AudioSegment.ffmpeg 中的属性名称更改为 AudioSegment.converter 因为我们现在支持ffmpeg和avconv。



请在分配到此属性之前检查您的版本使用哪个(它是从0.9.0版本开始的转换器 )


Im using this library for first time so Im not sure if this is a bug or Im not correctly doing something.

I want to export a file into mp3, the loading works perfectly:

wav=AudioSegment.from_wav(Path)  #If I execute only this line, there are no errors.

But when I try to export my file to mp3:

wav.export(r"WavOut.mp3",format="mp3")

It throws the following error:

WindowsError: [Error 2] The system cannot find the file specified

Full error report: http://pastebin.com/3CpZBkEK

I believe I am using the correct syntax. It creates the mp3 output file but absolutely empty, and the imput path is correct since:

os.startfile(Path) #Will work

Also, I registered ffmpeg, in windows path as:

;c:\ffmpeg\bin   #It is currently callable from any cmd prompt in windows.

What can be failing? Thanks!


After more testing, I found out its an encoding problem. If I set the output as "wav" it works. But I dont really know how should I install an mp3 encoder for it to work with pydub, so I changed the question to ask that, since its the real problem. ffmpeg is installed so I dont know what else to do :\

解决方案

I think it's unable to find the ffmpeg binary. Python has wave support built in, so pydub doesn't require ffmpeg to open/close/modify wave files.

Try assigning the location of the ffmpeg binary before you use it like so:

from pydub import AudioSegment
AudioSegment.converter = "c:\ffmpeg\bin\ffmpeg.exe"

wav = AudioSegment.from_wav(Path)  #If I execute only this line, there are no errors.
wav.export(r"WavOut.mp3",format="mp3")

edit: We've change changed the name of the property from AudioSegment.ffmpeg to AudioSegment.converter because we now support both ffmpeg and avconv.

Please check which your version uses before assigning to this property (it's "converter" starting in the 0.9.0 release)

这篇关于使用pydub导出时出错 - 如何为pydub安装mp3编解码器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆