python - 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\
解决方案
推荐阅读
- java - com.google.cloud.ServiceOptions$Builder 类型无法解析。它是从所需的 .class 文件中间接引用的
- django - 如何检查 Django 中 m2m 字段中值的出现?
- sql-server - 使用单个事务范围时获取 TransactionInDoubtException
- php - 我应该什么时候发送 JWT 刷新令牌?
- jaeger - 在 jaeger 中只跟踪错误痕迹,在 jaeger 中只找出错误痕迹
- maxima - 用于检查表达式形式的 Maxima 块
- asp.net - 使用 NPGSQL 在 Asp.Net Core 的 DbContextOptionsBuilder 中添加客户端证书
- python - 对熊猫数据框系列值进行分类
- r - 保存 R 脚本会导致空文件
- java - IntelliJ 无法运行:找不到主类。终端运行得很好