14
14
from video import extract_video_info
15
15
16
16
17
- THRESHOLD_NS = 10 * 1000 * 1000 # millis * micros * nanos
17
+ DEFAULT_THRESHOLD_MILLIS = 10
18
+ DEFAULT_THRESHOLD_NANOS = DEFAULT_THRESHOLD_MILLIS * 1000 * 1000 # millis * micros * nanos
18
19
19
20
20
21
def scan_session_dir (input_dir : Path ) -> Tuple [List [str ], List [pd .DataFrame ], List [str ]]:
@@ -66,14 +67,13 @@ def scan_session_dir(input_dir: Path) -> Tuple[List[str], List[pd.DataFrame], Li
66
67
#
67
68
#
68
69
#
69
- def main (input_dir : Path , output_dir : Path ):
70
+ def main (input_dir : Path , output_dir : Path , threshold_ns : int ):
70
71
71
72
print (f"Scanning dir { str (input_dir )} ..." )
72
73
clientIDs , df_list , mp4_list = scan_session_dir (input_dir )
73
74
74
75
n_clients = len (clientIDs )
75
76
76
-
77
77
#
78
78
# Print collected info
79
79
for i in range (n_clients ):
@@ -97,18 +97,21 @@ def main(input_dir: Path, output_dir: Path):
97
97
# Find time ranges
98
98
min_common , max_common = compute_time_range (repaired_df_list )
99
99
# Trim the data frames to the time range
100
- trimmed_dataframes = trim_repaired_into_interval (repaired_df_list , min_common , max_common , THRESHOLD_NS )
100
+ trimmed_dataframes = trim_repaired_into_interval (repaired_df_list , min_common , max_common , threshold_ns )
101
101
102
102
assert len (clientIDs ) == len (trimmed_dataframes ), f"Expected { len (clientIDs )} trimmed dataframes. Found f{ len (trimmed_dataframes )} "
103
103
104
104
# Check that all the resulting dataframes have the same number of rows
105
+ print ("Checking if all clients we have the same number of frames in the repaired amd trimmed tables..." )
105
106
client0ID = clientIDs [0 ]
106
107
client0size = len (trimmed_dataframes [0 ])
107
- print (f"For client { client0ID } : { client0size } frames" )
108
+ print (f"Client { client0ID } has { client0size } frames. " )
108
109
for cID , df in zip (clientIDs [1 :], trimmed_dataframes [1 :]):
109
110
dfsize = len (df )
110
111
if client0size != dfsize :
111
- raise Exception (f"For client { cID } : expecting { client0size } frames, found { dfsize } " )
112
+ raise Exception (f"For client { cID } : expecting { client0size } frames. Found { dfsize } ."
113
+ f" This might be due to an excessive phase offset during recording."
114
+ f" Try to increase the threshold." )
112
115
113
116
print ("Good. All trimmed dataframes have the same number of entries." )
114
117
@@ -152,16 +155,25 @@ def main(input_dir: Path, output_dir: Path):
152
155
"--outfolder" , "-o" , type = str , help = "The folder where the repaired and aligned frames will be stored." ,
153
156
required = True
154
157
)
158
+ parser .add_argument (
159
+ "--threshold" , "-t" , type = int , help = "The allowed difference in ms between corresponding frames on different videos."
160
+ " Increase this is post processing fails with trimmed tables of different sizes."
161
+ f" Default is now { DEFAULT_THRESHOLD_MILLIS } ms." ,
162
+ required = False ,
163
+ default = DEFAULT_THRESHOLD_MILLIS
164
+ )
155
165
156
166
args = parser .parse_args ()
157
167
158
168
infolder = Path (args .infolder )
159
169
outfolder = Path (args .outfolder )
170
+ threshold_millis = args .threshold
171
+ threshold_nanos = threshold_millis * 1000 * 1000
160
172
161
173
if not infolder .exists ():
162
174
raise Exception (f"Input folder '{ infolder } ' doesn't exist." )
163
175
164
176
if not outfolder .exists ():
165
177
raise Exception (f"Output folder '{ outfolder } ' doesn't exist." )
166
178
167
- main (infolder , outfolder )
179
+ main (infolder , outfolder , threshold_nanos )
0 commit comments