generate_videos.py
Go to the documentation of this file.
00001 # vim: expandtab:ts=4:sw=4
00002 import os
00003 import argparse
00004 import show_results
00005 
00006 
00007 def convert(filename_in, filename_out, ffmpeg_executable="ffmpeg"):
00008     import subprocess
00009     command = [ffmpeg_executable, "-i", filename_in, "-c:v", "libx264",
00010                "-preset", "slow", "-crf", "21", filename_out]
00011     subprocess.call(command)
00012 
00013 
00014 def parse_args():
00015     """ Parse command line arguments.
00016     """
00017     parser = argparse.ArgumentParser(description="Siamese Tracking")
00018     parser.add_argument(
00019         "--mot_dir", help="Path to MOTChallenge directory (train or test)",
00020         required=True)
00021     parser.add_argument(
00022         "--result_dir", help="Path to the folder with tracking output.",
00023         required=True)
00024     parser.add_argument(
00025         "--output_dir", help="Folder to store the videos in. Will be created "
00026         "if it does not exist.",
00027         required=True)
00028     parser.add_argument(
00029         "--convert_h264", help="If true, convert videos to libx264 (requires "
00030         "FFMPEG", default=False)
00031     parser.add_argument(
00032         "--update_ms", help="Time between consecutive frames in milliseconds. "
00033         "Defaults to the frame_rate specified in seqinfo.ini, if available.",
00034         default=None)
00035     return parser.parse_args()
00036 
00037 
00038 if __name__ == "__main__":
00039     args = parse_args()
00040 
00041     os.makedirs(args.output_dir, exist_ok=True)
00042     for sequence_txt in os.listdir(args.result_dir):
00043         sequence = os.path.splitext(sequence_txt)[0]
00044         sequence_dir = os.path.join(args.mot_dir, sequence)
00045         if not os.path.exists(sequence_dir):
00046             continue
00047         result_file = os.path.join(args.result_dir, sequence_txt)
00048         update_ms = args.update_ms
00049         video_filename = os.path.join(args.output_dir, "%s.avi" % sequence)
00050 
00051         print("Saving %s to %s." % (sequence_txt, video_filename))
00052         show_results.run(
00053             sequence_dir, result_file, False, None, update_ms, video_filename)
00054 
00055     if not args.convert_h264:
00056         import sys
00057         sys.exit()
00058     for sequence_txt in os.listdir(args.result_dir):
00059         sequence = os.path.splitext(sequence_txt)[0]
00060         sequence_dir = os.path.join(args.mot_dir, sequence)
00061         if not os.path.exists(sequence_dir):
00062             continue
00063         filename_in = os.path.join(args.output_dir, "%s.avi" % sequence)
00064         filename_out = os.path.join(args.output_dir, "%s.mp4" % sequence)
00065         convert(filename_in, filename_out)


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Tue Jul 2 2019 19:41:07