@@ -70,10 +70,10 @@ def frames_to_video(fps, frames, path, name, colorvids_bitrate=None):
70
70
priority = [('avi' , 'png' ), ('avi' , 'rawvideo' ), ('mp4' , 'libx264' ), ('webm' , 'libvpx' )]
71
71
if colorvids_bitrate :
72
72
priority = reversed (priority )
73
- for format , codec in priority :
73
+ for v_format , codec in priority :
74
74
try :
75
75
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 )
77
77
done = True
78
78
break
79
79
except :
@@ -83,19 +83,31 @@ def frames_to_video(fps, frames, path, name, colorvids_bitrate=None):
83
83
84
84
85
85
def 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
+
86
95
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)
89
96
# TODO: Detect cuts and process segments separately
90
-
91
97
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
99
111
100
112
101
113
def gen_video (video , outpath , inp , custom_depthmap = None , colorvids_bitrate = None , smoothening = 'none' ):
0 commit comments