@@ -70,10 +70,10 @@ def frames_to_video(fps, frames, path, name, colorvids_bitrate=None):
7070 priority = [('avi' , 'png' ), ('avi' , 'rawvideo' ), ('mp4' , 'libx264' ), ('webm' , 'libvpx' )]
7171 if colorvids_bitrate :
7272 priority = reversed (priority )
73- for format , codec in priority :
73+ for v_format , codec in priority :
7474 try :
7575 br = f'{ colorvids_bitrate } k' if codec not in ['png' , 'rawvideo' ] else None
76- clip .write_videofile (os .path .join (path , f"{ name } .{ format } " ), codec = codec , bitrate = br )
76+ clip .write_videofile (os .path .join (path , f"{ name } .{ v_format } " ), codec = codec , bitrate = br )
7777 done = True
7878 break
7979 except :
@@ -83,19 +83,31 @@ def frames_to_video(fps, frames, path, name, colorvids_bitrate=None):
8383
8484
8585def process_predicitons (predictions , smoothening = 'none' ):
86+ def global_scaling (objs , a = None , b = None ):
87+ """Normalizes objs, but uses (a, b) instead of (minimum, maximum) value of objs, if supplied"""
88+ normalized = []
89+ min_value = a if a is not None else min ([obj .min () for obj in objs ])
90+ max_value = b if b is not None else max ([obj .max () for obj in objs ])
91+ for obj in objs :
92+ normalized += [(obj - min_value ) / (max_value - min_value )]
93+ return normalized
94+
8695 print ('Processing generated depthmaps' )
87- # TODO: Smart normalizing (drop 0.001% of top and bottom values from the video/every cut)
88- # TODO: Smoothening between frames (use splines)
8996 # TODO: Detect cuts and process segments separately
90-
9197 if smoothening == 'none' :
92- input_depths = []
93- preds_min_value = min ([pred .min () for pred in predictions ])
94- preds_max_value = max ([pred .max () for pred in predictions ])
95- for pred in predictions :
96- norm = (pred - preds_min_value ) / (preds_max_value - preds_min_value ) # normalize to [0; 1]
97- input_depths += [norm ]
98- return input_depths
98+ return global_scaling (predictions )
99+ elif smoothening == 'experimental' :
100+ processed = []
101+ clip = lambda val : min (max (0 , val ), len (predictions ) - 1 )
102+ for i in range (len (predictions )):
103+ f = np .zeros_like (predictions [i ])
104+ for u , mul in enumerate ([0.10 , 0.20 , 0.40 , 0.20 , 0.10 ]): # Eyeballed it, math person please fix this
105+ f += mul * predictions [clip (i + (u - 2 ))]
106+ processed += [f ]
107+ # This could have been deterministic monte carlo... Oh well, this version is faster.
108+ a , b = np .percentile (np .stack (processed ), [0.5 , 99.5 ])
109+ return global_scaling (predictions , a , b )
110+ return predictions
99111
100112
101113def gen_video (video , outpath , inp , custom_depthmap = None , colorvids_bitrate = None , smoothening = 'none' ):
0 commit comments