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 /
有两个问题:1)需要将'-bsf:a aac_adtstoasc'分隔为'-bsf:a','aac_adtstoasc'
2)“需要删除concat周围的引号,因为仅在shell中运行直接命令时才需要使用引号”>