gpt4 book ai didi

python - 最后一个子进程调用在 FFMPEG 的串联代码中不起作用。我应该如何解决这个问题?

转载 作者:行者123 更新时间:2023-12-04 23:13:15 26 4
gpt4 key购买 nike

clips = []

#generates a list of mp4 files in a folder
def clipFinder(CurrentDir, fileType):
clips.clear()
for r,d,f in os.walk(CurrentDir):
for file in f:
if fileType in file:
clips.append(r+file)
random.shuffle(clips)

#removes all files that have the string 'vod' in them as they cause problems during concatenation
def removeVods(r):
for f in clips:
if 'vod' in clips:
os.remove(r+f)

#generates a string using the clips list to insert into the ffmpeg command
def clipString():
string = 'intermediate'
clipList = []
clipNum = 1
for f in clips:
clipList.append(string+str(clipNum)+'.ts'+'|')
clipNum+=1
string1 = ''.join(clipList)
string2 = string1[0:len(string1)-1]
return string2

#concatenates the mp4 files in the clipString
def concatFiles():
clipFinder('***', '.mp4')
removeVods('***')
i = 0
intermediates = []
for f in clips:
subprocess.call(['***', '-i', clips[i], '-c', 'copy', '-bsf:v', 'h264_mp4toannexb', '-f', 'mpegts', 'intermediate'+ str(i+1) +'.ts'])
i += 1
clipsLength = len(clips)
subprocess.call['***', '-i', '"concat:' + clipString() + '"', '-c', 'copy', '-bsf:a
aac_adtstoasc', 'output.mp4']

我正在尝试制作一个剪辑连接器,但最后一个子进程调用不会运行并且没有给我任何错误。当我运行脚本时,第一个 FFmpeg 调用工作正常并为我提供了我的中间 mp4 文件,但是,当我在终端中运行它时,第二个命令在我使用 subprocess.call 从 python 运行它时不起作用。

有问题的代码:
subprocess.call(['***', '-i', '"concat:' + clipString() + '"', '-c', 'copy', '-bsf:a aac_adtstoasc', 'output.mp4'])

所有带 * 的地方都是路径,例如:/davidscomputer/bin/ffmpeg/

最佳答案

问题代码:
subprocess.call['***', '-i', '"concat:' + clipString() + '"', '-c', 'copy', '-bsf:a aac_adtstoasc', 'output.mp4 ']

解决方案:
commandString = ['/Users/teoscomputer/bin/ffmpeg', '-i', 'concat:' + clipString(), '-c', 'copy', '-bsf:a', 'aac_adtstoasc', '输出.mp4']
subprocess.Popen(命令字符串)

有两个问题:
1) '-bsf:a aac_adtstoasc' 需要分成, '-bsf:a', 'aac_adtstoasc'

2) concat 周围的 "引号需要删除,因为它们仅在 shell 中运行直接命令时才需要

关于python - 最后一个子进程调用在 FFMPEG 的串联代码中不起作用。我应该如何解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59041316/

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