首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Python中使用FFMPEG时,是什么导致了此错误?

在Python中使用FFMPEG时,是什么导致了此错误?
EN

Stack Overflow用户
提问于 2022-05-27 01:58:30
回答 1查看 281关注 0票数 0

我正在尝试将MP3转换为OGG,但它不起作用。有什么问题吗?音频文件的路径是正确的。"ffmpeg.exe“位于脚本目录中。

程序中的代码片段:

代码语言:javascript
运行
复制
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

但是,此代码运行良好:

代码语言:javascript
运行
复制
import ffmpeg

inputfile = ffmpeg.input("example.mp3")
iAudio = inputfile.audio
stream = ffmpeg.output(iAudio, "example.ogg")
ffmpeg.run(stream)

错误:

代码语言:javascript
运行
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-30 10:43:57

@Rotem

在inp = ffmpeg.input( audioPath )之前添加print(audioPath)和print( destPath ) (或使用调试器获取字符串),并将audioPath和destPath的值添加到您的问题中。错误必须是audioPath和destPath值错误的结果。

谢谢你告诉我!我查看了传递给函数的路径,发现了问题。

结果发现这个问题是个变数。都是关于范围的。文件的路径没有分配给audioFolder,因为我没有告诉Python变量是全局的。

在此之前:

代码语言:javascript
运行
复制
audioFolder = selectedAudioFolder

之后:

代码语言:javascript
运行
复制
global audioFolder
audioFolder = selectedAudioFolder

一切都成功了!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72399692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档