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