def main(): global pid global VERBOSE global SILENT global infilename global outfilename global tmax global time_offset parser = argparse.ArgumentParser( description='Remove ARIB formatted Closed Caption information from an MPEG TS file and format the results as a standard .ass subtitle file.') parser.add_argument('infile', help='Input filename (MPEG2 Transport Stream File)', type=str) parser.add_argument('-o', '--outfile', help='Output filename (.ass subtitle file)', type=str, default=None) parser.add_argument('-p', '--pid', help='Specify a PID of a PES known to contain closed caption info (tool will attempt to find the proper PID if not specified.).', type=int, default=-1) parser.add_argument('-v', '--verbose', help='Verbose output.', action='store_true') parser.add_argument('-q', '--quiet', help='Does not write to stdout.', action='store_true') parser.add_argument('-t', '--tmax', help='Subtitle display time limit (seconds).', type=int, default=5) parser.add_argument('-m', '--timeoffset', help='Shift all time values in generated .ass file by indicated floating point offset in seconds.', type=float, default=0.0) args = parser.parse_args() pid = args.pid infilename = args.infile outfilename = infilename + ".ass" if args.outfile is not None: outfilename = args.outfile SILENT = args.quiet VERBOSE = args.verbose tmax = args.tmax time_offset = args.timeoffset if not os.path.exists(infilename) and not SILENT: print 'Input filename :' + infilename + " does not exist." sys.exit(-1) ts = TS(infilename) ts.Progress = OnProgress ts.OnTSPacket = OnTSPacket ts.OnESPacket = OnESPacket ts.Parse() if pid < 0 and not SILENT: print("*** Sorry. No ARIB subtitle content was found in file: " + infilename + " ***") sys.exit(-1) if ass and not ass.file_written() and not SILENT: print("*** Sorry. No nonempty ARIB closed caption content found in file " + infilename + " ***") sys.exit(-1) sys.exit(0)
def main(): global pid parser = argparse.ArgumentParser(description='Draw CC Packets from MPG2 Transport Stream file.') parser.add_argument('infile', help='Input filename (MPEG2 Transport Stream File)', type=str) parser.add_argument('-p', '--pid', help='Specify a PID of a PES known to contain closed caption info (tool will attempt to find the proper PID if not specified.).', type=int, default=-1) args = parser.parse_args() infilename = args.infile pid = args.pid if not os.path.exists(infilename): print 'Input filename :' + infilename + " does not exist." os.exit(-1) ts = TS(infilename) ts.Progress = OnProgress ts.OnTSPacket = OnTSPacket ts.OnESPacket = OnESPacket ts.Parse()
def OnTSPacket(packet): """ Callback invoked on the successful extraction of a single TS packet from a ts file :param packet: The entire packet (header and payload) as a string :return: None """ global initial_timestamp global elapsed_time_s #pcr (program count record) can be used to calculate elapsed time in seconds # we've read through the .ts file pcr = TS.get_pcr(packet) if pcr > 0: current_timestamp = pcr initial_timestamp = initial_timestamp or current_timestamp delta = current_timestamp - initial_timestamp elapsed_time_s = float(delta) / 90000.0
def OnTSPacket(packet): """ Callback invoked on the successful extraction of a single TS packet from a ts file :param packet: The entire packet (header and payload) as a string :return: None """ global initial_timestamp global elapsed_time_s global time_offset #pcr (program count record) can be used to calculate elapsed time in seconds # we've read through the .ts file pcr = TS.get_pcr(packet) if pcr > 0: current_timestamp = pcr initial_timestamp = initial_timestamp or current_timestamp delta = current_timestamp - initial_timestamp elapsed_time_s = float(delta) / 90000.0 + time_offset
def main(): global pid global VERBOSE global SILENT global infilename global outfilename global tmax global time_offset parser = argparse.ArgumentParser( description='Remove ARIB formatted Closed Caption information from an MPEG TS file and format the results as a standard .ass subtitle file.') parser.add_argument('infile', help='Input filename (MPEG2 Transport Stream File)', type=str) parser.add_argument('-o', '--outfile', help='Output filename (.ass subtitle file)', type=str, default=None) parser.add_argument('-p', '--pid', help='Specify a PID of a PES known to contain closed caption info (tool will attempt to find the proper PID if not specified.).', type=int, default=-1) parser.add_argument('-v', '--verbose', help='Verbose output.', action='store_true') parser.add_argument('-q', '--quiet', help='Does not write to stdout.', action='store_true') parser.add_argument('-t', '--tmax', help='Subtitle display time limit (seconds).', type=int, default=5) parser.add_argument('-m', '--timeoffset', help='Shift all time values in generated .ass file by indicated floating point offset in seconds.', type=float, default=0.0) args = parser.parse_args() pid = args.pid infilename = args.infile outfilename = infilename + ".ass" if args.outfile is not None: outfilename = args.outfile SILENT = args.quiet VERBOSE = args.verbose tmax = args.tmax time_offset = args.timeoffset if not os.path.exists(infilename) and not SILENT: print 'Input filename :' + infilename + " does not exist." sys.exit(-1) ts = TS(infilename) ts.Progress = OnProgress ts.OnTSPacket = OnTSPacket ts.OnESPacket = OnESPacket try: ts.Parse() except Exception as ex: if not SILENT: print("*** Sorry, " + str(ex)) sys.exit(-1) if pid < 0 and not SILENT: print("*** Sorry. No ARIB subtitle content was found in file: " + infilename + " ***") sys.exit(-1) if ass and not ass.file_written() and not SILENT: print("*** Sorry. No nonempty ARIB closed caption content found in file " + infilename + " ***") sys.exit(-1) sys.exit(0)