0
我遇到了一個我無法理解的問題。我正在給我所做的和我面臨的問題。爲什麼我不能使用python和optparser運行腳本
這裏是我的代碼:
#! /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時,腳本運行良好!
這與'optparse'無關,但與'dvbobjects.PSI.PAT'無關。 – 2013-10-23 12:21:53
'#python flush bug'?你那是什麼意思?也許你應該用'out.close()'關閉你的文件,而不是隻提到'out.close'這個方法...... IOW,真正執行調用'()'。 – glglgl
那麼爲什麼上面的代碼運行良好,沒有optparse – AnkushSeth