Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带子进程的avconv_Python_Ffmpeg_Subprocess - Fatal编程技术网

Python 带子进程的avconv

Python 带子进程的avconv,python,ffmpeg,subprocess,Python,Ffmpeg,Subprocess,似乎我从来没有真正地设法去了解子流程。此命令行在bash中工作 avconv -i "concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts" -vcodec copy -acodec copy /tmp/

似乎我从来没有真正地设法去了解子流程。此命令行在bash中工作

avconv -i "concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts" -vcodec copy -acodec copy /tmp/test1.ts
如果我尝试这个:

cmdline = ['avconv', '-i "concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts"', '-vcodec copy', '-acodec copy', '/tmp/test1.ts']
subprocess.call(cmdline)
它退出avconv时出现以下错误:

avconv version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
  built on Jun 12 2012 16:52:09 with gcc 4.6.3
Unrecognized option 'i "concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts"'
Failed to set value '-vcodec copy' for option 'i "concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts"'
1
我尝试了一些变体(包括shell=True),但我无法解决问题

更新 Cjb给出了一个非常有效的答案。但我真正的代码更复杂。我相信很难从中得到什么。但我把它放在这里,以防万一我错过了一个奥布沃伊斯问题

def run_avconv(output_dir, fnames):
    full_fnames = [os.path.join(output_dir, fname.replace('\n', ''))
                   for fname in fnames]
    concatted_files = '|'.join(full_fnames)
    cmd_line = [AVCONV_CMD,
                '-i',
                '"concat:' + concatted_files + '"',
                '-vcodec',
                'copy',
                '-acodec',
                'copy',
                os.path.join(output_dir, 'out.ts')]
    subprocess.Popen(cmd_line)
完整的_fnames变量为:

['/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment2.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment3.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment4.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment5.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment6.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment7.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment8.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment9.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment10.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment11.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment12.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment13.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment14.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment15.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment16.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment17.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment18.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment19.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment20.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment21.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment22.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment23.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment24.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment25.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment26.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment27.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment28.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment29.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment30.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment31.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment32.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment33.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment34.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment35.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment36.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment37.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment38.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment39.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment40.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment41.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment42.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment43.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment44.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment45.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment46.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment47.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment48.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment49.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment50.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment51.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment52.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment53.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment54.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment55.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment56.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment57.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment58.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment59.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment60.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment61.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment62.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment63.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment64.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment65.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment66.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment67.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment68.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment69.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment70.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment71.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment72.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment73.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment74.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment75.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment76.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment77.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment78.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment79.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment80.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment81.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment82.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment83.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment84.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment85.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment86.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment87.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment88.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment89.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment90.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment91.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment92.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment93.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment94.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment95.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment96.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment97.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment98.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment99.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment100.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment101.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment102.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment103.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment104.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment105.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment106.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment107.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment108.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment109.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment110.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment111.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment112.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment113.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment114.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment115.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment116.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment117.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment118.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment119.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment120.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment121.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment122.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment123.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment124.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment125.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment126.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment127.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment128.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment129.ts',
 '/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment130.ts']
试试这个:

cmdline = [
    'avconv',
    '-i',
    'concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts',
    '-vcodec',
    'copy',
    '-acodec',
    'copy',
    '/tmp/test1.ts',
]
subprocess.call(cmdline)
您确实希望将每个单独的部分作为列表中的不同项目传递。

尝试以下方法:

cmdline = [
    'avconv',
    '-i',
    'concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts',
    '-vcodec',
    'copy',
    '-acodec',
    'copy',
    '/tmp/test1.ts',
]
subprocess.call(cmdline)

您确实希望将每个单独的部分作为列表中的不同项传递。

由@djc给出的答案是正确的,但是如果您希望通过复制和粘贴字符串来工作,您可以执行以下操作:

import shlex
from pprint import pprint

cmd = """avconv -i "concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts" -vcodec copy -acodec copy /tmp/test1.ts"""
for_subprocess = shlex.split(cmd)
pprint(for_subprocess)

['avconv',
 '-i',
 'concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts',
 '-vcodec',
 'copy',
 '-acodec',
 'copy',
 '/tmp/test1.ts']

@djc的答案是正确的,但是如果您想通过复制和粘贴字符串来工作,可以执行以下操作:

import shlex
from pprint import pprint

cmd = """avconv -i "concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts" -vcodec copy -acodec copy /tmp/test1.ts"""
for_subprocess = shlex.split(cmd)
pprint(for_subprocess)

['avconv',
 '-i',
 'concat:/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment0.ts|/tmp/BABAR_AND_THE_A-011A-hts-a-v1-cc3651d01841d748_Layer6/6148_Period1/segment1.ts',
 '-vcodec',
 'copy',
 '-acodec',
 'copy',
 '/tmp/test1.ts']

语法高亮显示不理解三重引号字符串+1,谢谢。很好的选择。虽然我不确定它是否解决了我现在分离所有部件时的(新)问题:-/语法高亮显示不理解三重引号字符串+1,谢谢。很好的选择。虽然我不确定它是否解决了我现在分离所有部件时的(新)问题:-/谢谢它确实有用。但这只是一个简单的例子。所以在我的真实代码中,它仍然不起作用。我将粘贴真正的代码作为编辑。也许有人会觉得有些不对劲。因为我不-/谢谢它确实有用。但这只是一个简单的例子。所以在我的真实代码中,它仍然不起作用。我将粘贴真正的代码作为编辑。也许有人会觉得有些不对劲。因为我不-/