在Python中使用FFMPEG时,是什么导致此错误?
我正在尝试将MP3转换为OGG,但它不起作用。有什么问题? 音频文件的路径是正确的。 “ ffmpeg.exe”在脚本目录中。
程序中的代码段:
def ProcessAudio(audioPath, destPath):
inp = ffmpeg.input(audioPath)
au = inp.audio
stream = ffmpeg.output(au, destPath)
ffmpeg.run(stream)
def Convert(listofmusic, pathofmsc, pathofdest, append):
count = 0
if len(listofmusic) >= 100:
for i in range(100):
count += 1
out = mscPath + "/" + pathofdest + "/" + "track" + str(count) + ".ogg"
print(out)
ProcessAudio(audioFolder + "/" + listofmusic[i], out)
break
count = 0
elif len(listofmusic) < 100:
for i in range(len(listofmusic)):
count += 1
mscP = mscPath.replace("/", "\\")
out = mscP + "\\" + pathofdest + "\\" + "track" + str(count) + ".ogg"
print(out)
audioProc = audioFolder + "\\" + listofmusic[i]
print(audioProc)
ProcessAudio(audioProc, out)
break
count = 0
但是,此代码正常工作:
import ffmpeg
inputfile = ffmpeg.input("example.mp3")
iAudio = inputfile.audio
stream = ffmpeg.output(iAudio, "example.ogg")
ffmpeg.run(stream)
错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Santila\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 75, in pressed
Convert(musicList, mscPath, oggFolder, cbVar.get())
File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 52, in Convert
ProcessAudio(audioProc, out)
File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 32, in ProcessAudio
ffmpeg.run(stream)
File "C:\Users\Santila\AppData\Local\Programs\Python\Python310\lib\site-packages\ffmpeg\_run.py", line 325, in run
raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)
I'm trying to convert MP3 to OGG but it doesn't work. What's the problem?
The paths to the audio files are correct. "ffmpeg.exe" is in the script directory.
Code snippet from the program:
def ProcessAudio(audioPath, destPath):
inp = ffmpeg.input(audioPath)
au = inp.audio
stream = ffmpeg.output(au, destPath)
ffmpeg.run(stream)
def Convert(listofmusic, pathofmsc, pathofdest, append):
count = 0
if len(listofmusic) >= 100:
for i in range(100):
count += 1
out = mscPath + "/" + pathofdest + "/" + "track" + str(count) + ".ogg"
print(out)
ProcessAudio(audioFolder + "/" + listofmusic[i], out)
break
count = 0
elif len(listofmusic) < 100:
for i in range(len(listofmusic)):
count += 1
mscP = mscPath.replace("/", "\\")
out = mscP + "\\" + pathofdest + "\\" + "track" + str(count) + ".ogg"
print(out)
audioProc = audioFolder + "\\" + listofmusic[i]
print(audioProc)
ProcessAudio(audioProc, out)
break
count = 0
However, this code works fine:
import ffmpeg
inputfile = ffmpeg.input("example.mp3")
iAudio = inputfile.audio
stream = ffmpeg.output(iAudio, "example.ogg")
ffmpeg.run(stream)
Error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Santila\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 75, in pressed
Convert(musicList, mscPath, oggFolder, cbVar.get())
File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 52, in Convert
ProcessAudio(audioProc, out)
File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 32, in ProcessAudio
ffmpeg.run(stream)
File "C:\Users\Santila\AppData\Local\Programs\Python\Python310\lib\site-packages\ffmpeg\_run.py", line 325, in run
raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@rotem
感谢您的提示!我查看了哪些路径传递到该功能并发现了问题。
事实证明,问题是一个变量。一切都与范围有关。该文件的路径未分配给AudioFolter,因为我没有告诉Python该变量是全局的。
之前:
之后:
一切都起作用!
@Rotem
Thanks for the tip! I looked at which paths are passed to the function and found the problem.
It turns out that the problem was a variable. It's all about scope. The path to the file was not assigned to audioFolder because I didn't tell Python that the variable was global.
Before:
After:
And it all works!