首页 > 解决方案 > PyDub 找不到 mp3 文件 (Windows)

问题描述

我有以下代码在尝试查找 mp3 文件时出错。链接是准确的(copyfile 函数工作得很好),这让我相信这是一个 PATH 问题或 ffmpeg。任何想法是什么推动了这一点?

代码:

from pydub import AudioSegment
import pydub
from shutil import copyfile

pydub.AudioSegment.ffmpeg = r"C:\ffmpeg\bin\ffmpeg.exe"
pydub.AudioSegment.converter = r"C:\ffmpeg\bin\ffmpeg.exe"

copyfile(link, link2)
sound = AudioSegment.from_mp3(link)
second_half = sound[:30]
second_half.export(file2, format="mp3")

错误:

C:\Users\xx\AppData\Local\Programs\Python\Python39\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:\Users\xx\AppData\Local\Programs\Python\Python39\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\xx\Desktop\Python\Accelerators\Zillow.py", line 12, in <module>
    sound = AudioSegment.from_mp3(link)
  File "C:\Users\xx\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
  File "C:\Users\xx\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
  File "C:\Users\xx\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
  File "C:\Users\xx\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\xx\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

命令

C:\>ffmpeg
'ffmpeg' is not recognized as an internal or external command,
operable program or batch file.

C:\>C:\ffmpeg\bin\ffmpeg.exe -codecs
ffmpeg version n4.4.1-20211101 Copyright (c) 2000-2021 the FFmpeg developers <------WORKS

小路:

C:\ffmpeg\bin\

标签: pythonpython-3.xffmpeg

解决方案


推荐阅读