generate_videos.py
Go to the documentation of this file.
1 # vim: expandtab:ts=4:sw=4
2 import os
3 import argparse
4 import show_results
5 
6 
7 def convert(filename_in, filename_out, ffmpeg_executable="ffmpeg"):
8  import subprocess
9  command = [ffmpeg_executable, "-i", filename_in, "-c:v", "libx264",
10  "-preset", "slow", "-crf", "21", filename_out]
11  subprocess.call(command)
12 
13 
14 def parse_args():
15  """ Parse command line arguments.
16  """
17  parser = argparse.ArgumentParser(description="Siamese Tracking")
18  parser.add_argument(
19  "--mot_dir", help="Path to MOTChallenge directory (train or test)",
20  required=True)
21  parser.add_argument(
22  "--result_dir", help="Path to the folder with tracking output.",
23  required=True)
24  parser.add_argument(
25  "--output_dir", help="Folder to store the videos in. Will be created "
26  "if it does not exist.",
27  required=True)
28  parser.add_argument(
29  "--convert_h264", help="If true, convert videos to libx264 (requires "
30  "FFMPEG", default=False)
31  parser.add_argument(
32  "--update_ms", help="Time between consecutive frames in milliseconds. "
33  "Defaults to the frame_rate specified in seqinfo.ini, if available.",
34  default=None)
35  return parser.parse_args()
36 
37 
38 if __name__ == "__main__":
39  args = parse_args()
40 
41  os.makedirs(args.output_dir, exist_ok=True)
42  for sequence_txt in os.listdir(args.result_dir):
43  sequence = os.path.splitext(sequence_txt)[0]
44  sequence_dir = os.path.join(args.mot_dir, sequence)
45  if not os.path.exists(sequence_dir):
46  continue
47  result_file = os.path.join(args.result_dir, sequence_txt)
48  update_ms = args.update_ms
49  video_filename = os.path.join(args.output_dir, "%s.avi" % sequence)
50 
51  print("Saving %s to %s." % (sequence_txt, video_filename))
53  sequence_dir, result_file, False, None, update_ms, video_filename)
54 
55  if not args.convert_h264:
56  import sys
57  sys.exit()
58  for sequence_txt in os.listdir(args.result_dir):
59  sequence = os.path.splitext(sequence_txt)[0]
60  sequence_dir = os.path.join(args.mot_dir, sequence)
61  if not os.path.exists(sequence_dir):
62  continue
63  filename_in = os.path.join(args.output_dir, "%s.avi" % sequence)
64  filename_out = os.path.join(args.output_dir, "%s.mp4" % sequence)
65  convert(filename_in, filename_out)
def convert(filename_in, filename_out, ffmpeg_executable="ffmpeg")
def run(sequence_dir, result_file, show_false_alarms=False, detection_file=None, update_ms=None, video_filename=None)
Definition: show_results.py:16


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Mon May 3 2021 03:03:27