Esempio n. 1
0
def main():
    """Main function, do the job"""

    # Global scope for args
    global args

    # Parse the arguments
    args = arguments_parser()

    # Read input file
    entries = subrip.parse(args.EVENT_FILE_IN)
    f = open(args.EVENT_FILE_OUT, 'w')

    for entry in entries:
        # Scale the time of each subtitle
        b_stamp = "%s" % entry.begin
        b_time = Time(text=b_stamp, sep_ms=',')
        b_time.milis += args.delay * 1000
        b_time.milis *= args.ratio
        e_stamp = "%s" % entry.end
        e_time = Time(text=e_stamp, sep_ms=',')
        e_time.milis += args.delay * 1000
        e_time.milis *= args.ratio
        f.write('%d\n%s --> %s\n' % (entry.number, b_time, e_time))
        f.write('%s\n' % entry.text)

    f.close()
Esempio n. 2
0
def read_events(file_path, start_timestamp):
	"""Read the events file"""
	# previous version: return evtfiles.parse(file_path)
	entries = subrip.parse(file_path)
	if start_timestamp == 0:
		start_timestamp = datetime.datetime.utcfromtimestamp(0)

	# Prepare the events array
	events = []

	# Parse each subtitle
	for entry in entries:

		# Match times
		entry.begin.subtractDate(start_timestamp)
		match_begin, match_end = match_times(entry.begin, entry.end)
		ident = entry.begin.milis

		if args.VIDEO_FILE:
			# By default we set the path of an image to be extracted from video
			image_file = "./images/event_" + str(ident) + ".jpg"
		else:
			image_file = ""

		try:
			# Detect if an image exists already
			detail = json.loads(entry.text)
			image_file = '../events_img/' + os.path.basename(detail['external']['files']['globalImage'])
		except:
			print "Cannot find image for event at %s" % entry.begin

		events.append(Event(id=ident, begin=entry.begin, end=entry.end, image_file=image_file))

	return events
Esempio n. 3
0
def main():
	"""Main function, do the job"""

	# Global scope for args
	global args

	# Parse the arguments
	args = arguments_parser()

	# Read input file
	entries = subrip.parse(args.EVENT_FILE_IN)
	f = open(args.EVENT_FILE_OUT, 'w')

	for entry in entries:
		# Scale the time of each subtitle
		b_stamp = "%s" % entry.begin
		b_time = Time(text=b_stamp, sep_ms=',')
		b_time.milis += args.delay * 1000
		b_time.milis *= args.ratio
		e_stamp = "%s" % entry.end
		e_time = Time(text=e_stamp, sep_ms=',')
		e_time.milis += args.delay * 1000
		e_time.milis *= args.ratio
		f.write('%d\n%s --> %s\n' % (entry.number, b_time, e_time))
		f.write('%s\n' % entry.text)

	f.close()
Esempio n. 4
0
def read_truths(file_path):
	"""Read the ground truth file"""

	# Read the file
	entries = subrip.parse(file_path)

	# Prepare the truths array
	truths = []

	# Parse each subtitle
	for entry in entries:

		# Look if this is a fall
		fall	  = is_valid(entry.text)
		ambiguous = is_ambiguous(entry.text)

		# If is is garbage skip
		if not fall or fall is None:
			continue

		entry_begin = entry.begin
		entry_end   = entry.end

		# Match times
		match_begin, match_end = match_times(entry_begin, entry_end)

		# Otherwise add to the truths array
		truths.append(Truth(id=entry.number,
							begin=entry_begin,
							end=entry_end,
							match_begin=match_begin,
							match_end=match_end,
							text=entry.text.strip(' \t\n\r'),
							is_valid=fall,
							is_ambiguous=ambiguous))

	return truths