我有一个我无法理解的问题。我正在给出我所做的以及我面临的问题。
这是我的代码:
#! /usr/bin/env python
import os
from dvbobjects.PSI.PAT import *
from optparse import OptionParser
#
# Shared values
#
parser = OptionParser()
parser.add_option( "--tsid",
help="input transportstream id", metavar="FILE")
(options, args) = parser.parse_args()
#############
avalpa_transport_stream_id = options.tsid # demo value, an official value should be demanded to dvb org
avalpa_original_transport_stream_id = 1#options.otsid # demo value, an official value should be demanded to dvb org
avalpa1_service_id = 1 # demo value
avalpa1_pmt_pid = 2031 #options.spmtid
output= './pat.ts'
#
# Program Association Table (ISO/IEC 13818-1 2.4.4.3)
#
pat = program_association_section(
transport_stream_id = avalpa_transport_stream_id,
program_loop = [
program_loop_item(
program_number = avalpa1_service_id,
PID = avalpa1_pmt_pid,
),
program_loop_item(
program_number = 0, # special program for the NIT
PID = 16,
),
],
version_number = 1, # you need to change the table number every time you edit, so the decoder will compare its version with the new one and update the table
section_number = 0,
last_section_number = 0,
)
#
# PSI marshalling and encapsulation
#
out = open("./pat.sec", "wb")
out.write(pat.pack())
out.close
out = open("./pat.sec", "wb") # python flush bug
out.close
os.system('/usr/local/bin/sec2ts 0 < ./pat.sec > '+ output)
#remove all sec files
os.system('rm *.sec')
和查询:./patconfig.py --tsid 1
和错误:
Traceback (most recent call last):
File "./patconfig.py", line 86, in <module>
out.write(pat.pack())
File "/usr/local/lib/python2.6/dist-packages/dvbobjects/MPEG/Section.py", line 94, in pack
self.__sanity_check()
File "/usr/local/lib/python2.6/dist-packages/dvbobjects/MPEG/Section.py", line 68, in __sanity_check
assert 0 <= self.table_id_extension <= 0xffff
AssertionError
请帮助我。我无法理解这个问题,当我不使用 optparser 时,脚本运行良好!!