@@ -59,7 +59,7 @@ def levels_options(parser: ArgumentParser) -> ArgumentParser:
59
59
def print_arr (arr : NDArray ) -> None :
60
60
print ("" )
61
61
print ("@start" )
62
- if arr .dtype == np .float64 :
62
+ if arr .dtype in ( np .float64 , np . float32 , np . float16 ) :
63
63
for a in arr :
64
64
sys .stdout .write (f"{ a :.20f} \n " )
65
65
elif arr .dtype == np .bool_ :
@@ -131,18 +131,49 @@ def main(sys_args: list[str] = sys.argv[1:]) -> None:
131
131
levels = Levels (src , tb , bar , False , log , strict = True )
132
132
try :
133
133
if method == "audio" :
134
- container = av .open (src .path , "r" )
135
- audio_stream = container .streams .audio [obj ["stream" ]]
136
- log .experimental (audio_stream .codec )
137
- print_arr_gen (iter_audio (audio_stream , tb ))
138
- container .close ()
134
+ if (arr := levels .read_cache ("audio" , (obj ["stream" ],))) is not None :
135
+ print_arr (arr )
136
+ else :
137
+ container = av .open (src .path , "r" )
138
+ audio_stream = container .streams .audio [obj ["stream" ]]
139
+ log .experimental (audio_stream .codec )
140
+
141
+ values = []
142
+
143
+ def value_storing_generator () -> Iterator [np .float32 ]:
144
+ for value in iter_audio (audio_stream , tb ):
145
+ values .append (value )
146
+ yield value
147
+
148
+ print_arr_gen (value_storing_generator ())
149
+ container .close ()
150
+
151
+ cache_array = np .array (values , dtype = np .float32 )
152
+ levels .cache (cache_array , "audio" , (obj ["stream" ],))
139
153
140
154
elif method == "motion" :
141
- container = av .open (src .path , "r" )
142
- video_stream = container .streams .video [obj ["stream" ]]
143
- log .experimental (video_stream .codec )
144
- print_arr_gen (iter_motion (video_stream , tb , obj ["blur" ], obj ["width" ]))
145
- container .close ()
155
+ mobj = (obj ["stream" ], obj ["width" ], obj ["blur" ])
156
+ if (arr := levels .read_cache ("motion" , mobj )) is not None :
157
+ print_arr (arr )
158
+ else :
159
+ container = av .open (src .path , "r" )
160
+ video_stream = container .streams .video [obj ["stream" ]]
161
+ log .experimental (video_stream .codec )
162
+
163
+ values = []
164
+
165
+ def value_storing_generator () -> Iterator [np .float32 ]:
166
+ for value in iter_motion (
167
+ video_stream , tb , obj ["blur" ], obj ["width" ]
168
+ ):
169
+ values .append (value )
170
+ yield value
171
+
172
+ print_arr_gen (value_storing_generator ())
173
+ container .close ()
174
+
175
+ cache_array = np .array (values , dtype = np .float32 )
176
+ levels .cache (cache_array , "motion" , mobj )
146
177
147
178
elif method == "subtitle" :
148
179
print_arr (levels .subtitle (** obj ))
0 commit comments