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

问题描述 投票:0回答:1
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 /

python ffmpeg concatenation mp4
1个回答
0
投票
解决方案:commandString = ['/ Users / teoscomputer / bin / ffmpeg','-i','concat:'+ clipString(),'-c','copy','-bsf:a','aac_adtstoasc','输出.mp4']subprocess.Popen(commandString)

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

2)“需要删除concat周围的引号,因为仅在shell中运行直接命令时才需要使用引号”>

© www.soinside.com 2019 - 2024. All rights reserved.