Ejemplo n.º 1
0
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)