0

这是 tsduck 手册中所写的命令:

tsp -I dvb -a 1 @ts1028.txt \
     -P svremove -s AlJazeeraEnglish \
     -P merge "tsp -I dvb -a 0 @ts1022.txt -P zap TV5MondeEurope" \
     -P analyze -i 30 -o merged.txt \
     -O dektec @modulation.txt

这是我的版本:

import sys
import subprocess

mod_values = { "bandwidth":             "8-mhz",
               "convolutional_rate":    "7/8",
               "frequency":             "578000000",
               "guard_interval":        "1/4",
               "dmb_constellation":     "64-QAM",
               "modulation":            "DVB-T"}

tsterinfo_rate = subprocess.run(['tsterinfo',
    "-h", mod_values["convolutional_rate"],
    "-g", mod_values["guard_interval"],
    "-c", mod_values["dmb_constellation"],
    "-s"], stdout=subprocess.PIPE, universal_newlines=True)

mod_values["dvb_bitrate"] = tsterinfo_rate.stdout

infile=sys.argv[1]

run_tsp = subprocess.run(['tsp',
    '--verbose',
    '-b', mod_values["dvb_bitrate"],
    '-I', 'null',
    '-P', 'merge',
        f'"tsp -I File {infile} --infinite"',
    '-P', 'pcrbitrate',
    '-P', 'regulate',
    '-O', 'dektec',
    '--frequency', mod_values["frequency"],
    '--modulation', mod_values["modulation"],
    '--guard-interval', mod_values["guard_interval"],
    '--convolutional-rate', mod_values["convolutional_rate"],
    '--dmb-constellation', mod_values["dmb_constellation"],
    '-s'])

如果我尝试将命令中的带引号部分保留为完整字符串,并且双引号中的空格围绕我的单引号,则会返回此错误:

/bin/sh: 1: tsp -I File ../Videos/myts.ts --infinite: not found

完全没有引号,它会错误地说输入太多,就像它直接进入没有引号的终端一样

蟒蛇 3.8.5,ubuntu 20.04

4

1 回答 1

0

在处理这个问题时,我发现我的 tsp 命令有一些问题。关于将引号传递给子进程的问题的答案似乎可以通过使用来解决

shell=True

在子流程选项中。然后,您可以将命令行参数作为一个大字符串而不是列表传递。

我将传输流作为参数并创建 CBR 输出以准备通过 Dektec DTU-215 混合的最终脚本是这样的:

    import sys
    import subprocess
    import json
    
    # set modulation parameters in dict in order to reference once for bitrate calc and use again for modulator setup
    mod_values = { "bandwidth":             "8-mhz",
                   "convolutional_rate":    "7/8",
                   "frequency":             "578000000",
                   "guard_interval":        "1/4",
                   "dmb_constellation":     "64-QAM",
                   "modulation":            "DVB-T"}
    
    # calculate modulated bitrate and add to dict
    tsterinfo_rate = subprocess.run(['tsterinfo',
        "-h", mod_values["convolutional_rate"],
        "-g", mod_values["guard_interval"],
        "-c", mod_values["dmb_constellation"],
        "-s"], stdout=subprocess.PIPE, universal_newlines=True)
    
    mod_values["dvb_bitrate"] = tsterinfo_rate.stdout.strip()
    
    # first argument is input file transport stream
    infile=sys.argv[1]
    
    # use mediainfo to calculate bitrate of input ts (must be CBR)
    infile_mediainfo = subprocess.run(["mediainfo",
        "--Output=JSON",
        infile],
        capture_output=True)
    
    print(infile_mediainfo)
    
    media_data = json.loads(infile_mediainfo.stdout)
    
    ts_bitrate = int(media_data["media"]["track"][0]["OverallBitRate"])
    
    print(f'ts_bitrate is: {ts_bitrate}')
    
    # without -t option we don't have a PAT to even merge our stream with
    # packet burst seems to make big difference to how smooth final playback is, default (16 according to docs) was jerky but 14 seems smooth
    run_tsp = subprocess.run(f'tsp \
                    --verbose \
                    -d \
                    -b {mod_values["dvb_bitrate"]} \
                    -I null \
                    -P regulate --packet-burst 14 \
                    -P merge \
                    -t \
                        "tsp -I file {infile} \
                        --infinite \
                        -P regulate -b {ts_bitrate}" \
                    -O dektec \
                    -f {mod_values["frequency"]} \
                    -m {mod_values["modulation"]} \
                    -g {mod_values["guard_interval"]} \
                    -r {mod_values["convolutional_rate"]} \
                    --dmb-constellation {mod_values["dmb_constellation"]} \
                    -s', shell=True)
于 2020-10-19T14:35:51.613 回答