gpt4 book ai didi

python - 在python中使用ffmpeg切割mp3 - 编解码器复制错误

转载 作者:行者123 更新时间:2023-12-01 03:36:06 24 4
gpt4 key购买 nike

def cut_file(file, start_time, end_time):
""" Cut the mp3 file with start and end time. """
output = file[:-4] + "_cut.mp3"
try:
os.remove(output)
except Exception:
pass
p=Popen(["ffmpeg", "-i", file, "-c:a copy -ss", start_time, "-to", end_time, output], stdout=PIPE)
p.communicate()
os.remove(file)
os.rename(output,file)
return file

当使用此函数剪切 mp3 文件时,我收到 ffmpeg 错误。错误是:

Unknown encoder '0:07'

为什么使用Python时ffmpeg无法识别复制命令?在 shell 中运行该命令不会给我任何错误。

我尝试更改参数的顺序,但这给了我同样的错误。

I got the code out of the official documentation.

最佳答案

由于您以列表方式传递所有参数(这是一个很好的做法),因此您需要按空间拆分所有参数,否则Popen将引用-保护包含空格的内容以尊重您通过的内容。

此参数“-c:a copy -ss”被解释为一个参数,这可能解释了为什么ffmpeg试图将您的开始时间作为编码器读取。

真正发出给系统调用的是:

ffmpeg -i file "-c:a copy -ss" start_time -to end_time output

这样做:

p=Popen(["ffmpeg", "-i", file, "-c:a","copy","-ss", start_time, "-to", end_time, output], stdout=PIPE)

关于python - 在python中使用ffmpeg切割mp3 - 编解码器复制错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40376865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com