【问题标题】:I am getting this error while converting .m4a files to .mp3将 .m4a 文件转换为 .mp3 时出现此错误
【发布时间】:2020-08-02 11:10:05
【问题描述】:

如图所示运行脚本时出现此错误

测试.py

from pydub import AudioSegment
wav_audio = AudioSegment.from_file("Broken Summer.m4a", format="m4a")

wav_audio.export("audio1.mp3", format="mp3")    

报错如下图

C:\Python\lib\site-packages\pydub\utils.py:170: 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)
C:\Python\lib\site-packages\pydub\utils.py:198: 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/karti/Documents/Python Programs/ChatApplication/deezer.py", line 13, in <module>
    wav_audio = AudioSegment.from_file("Broken Summer.m4a", format="m4a")
  File "C:\Python\lib\site-packages\pydub\audio_segment.py", line 685, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
  File "C:\Python\lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
  File "C:\Python\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

【问题讨论】:

  • 您是否也尝试过使用完整路径,例如 C:\Users\..\..\Broken Summer.m4a
  • 查看回溯的第二行,您必须安装给定的二进制文件之一。

标签: python ffmpeg mp3 mutagen


【解决方案1】:

即使添加了 ffmpeg 的依赖项,很可能该文件也不会被读取。由于 pydub 不读取 .m4a 文件这一事实。主要是因为'ffmpeg'不支持通过'libav'库的这种类型的文件。

我也遇到了这个问题。

【讨论】:

  • 我已经添加了完美的解决方案
【解决方案2】:

运行前pip install ffmpeg。

pip install ffmpeg-python

【讨论】:

  • 我已添加解决方案
【解决方案3】:

我得到了解决方案。 如果你已经安装了 ffmpeg 或 ffmpeg-python。卸载它。因为它不起作用 运行此命令

pip uninstall ffmpeg
pip uninstall ffmpeg-python

现在转到此链接https://ffmpeg.org/download.html

从这里下载 ffmpeg 并安装到 C:\ffmpeg 然后转到环境变量并在路径中添加一个新路径为 - C:\ffmpeg\bin 由于此路径包含 ffmpeg.exe 就是这样

现在假设您有要转换为 TEST.mp3 的 TEST.m4a 文件 只需复制并粘贴文件名并运行以下脚本。 注意:bewlo .py 文件应与 TEST.m4a 位于同一目录中,否则您需要在“CurrentFileName”变量中添加正确的路径 现在只需创建一个 .py 文件并粘贴此代码

import subprocess

CurrentFileName = 'TEST.m4a'
FinalFileName = 'TEST.mp3'

try:
    subprocess.call(['ffmpeg', '-i', f'{CurrentFileName}', f'{FinalFileName}'])

except Exception as e:
    print(e)
    print('Error While Converting Audio')

ch = input('Press Enter to Close')

这对我来说非常适合我想要的。 :) 如果我的答案不清楚,请在这里告诉我,或者你可以给我发邮件 - kartikeyvaish99@gmail.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    相关资源
    最近更新 更多