/
timelapse.py
executable file
·178 lines (168 loc) · 4.69 KB
/
timelapse.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
import sys
import argparse
from capture import capture
from clean import clean
from convert import convert
def _parse_arguments():
parser = argparse.ArgumentParser(
description="Capture a timelapse of some activity."
)
parser.add_argument(
"-d", "--debug",
action="store_true",
dest="debug",
help="print debugging information"
)
subparsers = parser.add_subparsers(dest='command')
# Capture command
capture_parser = subparsers.add_parser(
'capture', aliases=['cap'],
help="capture a timelapse"
)
capture_parser.add_argument(
"destination",
type=str,
action="store",
help="destination directory for timelapse captures"
)
# Consider nargs='*' to allow a default of capturing all processes.
capture_parser.add_argument(
"windows",
metavar='W',
type=str,
nargs='+',
help="title of window(s) that should be captured when active"
)
capture_parser.add_argument(
"-i", "--interval",
metavar='I',
dest="interval",
action="store",
default=3,
type=int,
help="the period between screenshots, in seconds"
)
capture_parser.add_argument(
"-s", "--single",
dest="single",
action="store_true",
help=(
"indicates that the destination should be treated as a single image"
" sequence instead of storing separate sessions in subdirectories"
)
)
clean_parser = subparsers.add_parser(
'clean',
help="detect and remove bad frames from the image sequence"
)
clean_parser.add_argument(
"source",
type=str,
action="store",
help="source directory for image sequences"
)
clean_parser.add_argument(
"specification",
type=str,
action="store",
nargs="+",
help="specification of what to check for in the images"
)
clean_parser.add_argument(
"--destination",
dest="destination",
metavar='D',
type=str,
action="store",
default="rejected",
help="destination directory for bad frames"
)
clean_parser.add_argument(
"--delete",
action="store_true",
dest="delete_immediately",
help=(
"delete detected frames immediately instead of moving them to a"
" rejection directory"
)
)
clean_parser.add_argument(
"-s", "--single",
action="store_true",
dest="single",
help="only check the specified directory instead of looking for subdirectories"
)
clean_parser.add_argument(
"--test",
action="store_true",
dest="test",
help="check the rules but do not move or delete the frames"
)
compile_parser = subparsers.add_parser(
'convert', aliases=['con'],
help="prepare video clips"
)
compile_parser.add_argument(
"source",
type=str,
action="store",
help="source directory for image sequences"
)
compile_parser.add_argument(
"--destination",
dest="destination",
metavar='D',
type=str,
action="store",
default="clips",
help="destination directory for raw clips"
)
compile_parser.add_argument(
"-f",
"--framerate",
metavar='F',
dest="framerate",
action="store",
default=20,
type=int,
help="the framerate to use for the video clips"
) # TODO: Determine best default
compile_parser.add_argument(
"-s",
"--single",
dest="single",
action="store_true",
help=(
"indicates that the source should be treated as a single image"
" sequence instead of separate sessions stored in subdirectories"
)
)
compile_parser.add_argument(
"--skip-pad-clip",
action="store_true",
dest="skip_pad_clip",
help="skip creation of a padding clip based on the final frame"
)
args = parser.parse_args()
return args
def _main():
args = _parse_arguments()
global _debug
_debug = args.debug
try:
if args.command in ['capture', 'cap']:
capture(args)
elif args.command in ['clean']:
clean(args)
elif args.command in ['convert', 'con']:
convert(args)
except KeyboardInterrupt:
# TODO: Maybe track some statistics and print them on exit.
# Redisplay the cursor
sys.stdout.write("\x1b[?25h")
sys.stdout.flush()
print()
sys.exit(0)
if __name__ == "__main__":
_main()