@@ -88,7 +88,7 @@ def obj_tag(tag: str, tb: Fraction, obj: dict[str, Any]) -> str:
88
88
return key
89
89
90
90
91
- def iter_audio (src , tb : Fraction , stream : int = 0 ) -> Iterator [float ]:
91
+ def iter_audio (src , tb : Fraction , stream : int = 0 ) -> Iterator [np . float32 ]:
92
92
fifo = AudioFifo ()
93
93
try :
94
94
container = av .open (src .path , "r" )
@@ -117,13 +117,13 @@ def iter_audio(src, tb: Fraction, stream: int = 0) -> Iterator[float]:
117
117
audio_chunk = fifo .read (current_size )
118
118
assert audio_chunk is not None
119
119
arr = audio_chunk .to_ndarray ().flatten ()
120
- yield float ( np .max (np .abs (arr ) ))
120
+ yield np .max (np .abs (arr ))
121
121
122
122
finally :
123
123
container .close ()
124
124
125
125
126
- def iter_motion (src , tb , stream : int , blur : int , width : int ) -> Iterator [float ]:
126
+ def iter_motion (src , tb , stream : int , blur : int , width : int ) -> Iterator [np . float32 ]:
127
127
container = av .open (src .path , "r" )
128
128
129
129
video = container .streams .video [stream ]
@@ -155,11 +155,11 @@ def iter_motion(src, tb, stream: int, blur: int, width: int) -> Iterator[float]:
155
155
156
156
current_frame = frame .to_ndarray ()
157
157
if prev_frame is None :
158
- value = 0.0
158
+ value = np . float32 ( 0.0 )
159
159
else :
160
160
# Use `int16` to avoid underflow with `uint8` datatype
161
161
diff = np .abs (prev_frame .astype (np .int16 ) - current_frame .astype (np .int16 ))
162
- value = np .count_nonzero (diff ) / total_pixels
162
+ value = np .float32 ( np . count_nonzero (diff ) / total_pixels )
163
163
164
164
for _ in range (index - prev_index ):
165
165
yield value
@@ -237,7 +237,7 @@ def cache(self, tag: str, obj: dict[str, Any], arr: np.ndarray) -> np.ndarray:
237
237
238
238
return arr
239
239
240
- def audio (self , stream : int ) -> NDArray [np .float64 ]:
240
+ def audio (self , stream : int ) -> NDArray [np .float32 ]:
241
241
if stream >= len (self .src .audios ):
242
242
raise LevelError (f"audio: audio stream '{ stream } ' does not exist." )
243
243
@@ -256,12 +256,12 @@ def audio(self, stream: int) -> NDArray[np.float64]:
256
256
bar = self .bar
257
257
bar .start (inaccurate_dur , "Analyzing audio volume" )
258
258
259
- result = np .zeros ((inaccurate_dur ), dtype = np .float64 )
259
+ result = np .zeros ((inaccurate_dur ), dtype = np .float32 )
260
260
index = 0
261
261
for value in iter_audio (self .src , self .tb , stream ):
262
262
if index > len (result ) - 1 :
263
263
result = np .concatenate (
264
- (result , np .zeros ((len (result )), dtype = np .float64 ))
264
+ (result , np .zeros ((len (result )), dtype = np .float32 ))
265
265
)
266
266
result [index ] = value
267
267
bar .tick (index )
@@ -270,7 +270,7 @@ def audio(self, stream: int) -> NDArray[np.float64]:
270
270
bar .end ()
271
271
return self .cache ("audio" , {"stream" : stream }, result [:index ])
272
272
273
- def motion (self , stream : int , blur : int , width : int ) -> NDArray [np .float64 ]:
273
+ def motion (self , stream : int , blur : int , width : int ) -> NDArray [np .float32 ]:
274
274
if stream >= len (self .src .videos ):
275
275
raise LevelError (f"motion: video stream '{ stream } ' does not exist." )
276
276
@@ -289,12 +289,12 @@ def motion(self, stream: int, blur: int, width: int) -> NDArray[np.float64]:
289
289
bar = self .bar
290
290
bar .start (inaccurate_dur , "Analyzing motion" )
291
291
292
- result = np .zeros ((inaccurate_dur ), dtype = np .float64 )
292
+ result = np .zeros ((inaccurate_dur ), dtype = np .float32 )
293
293
index = 0
294
294
for value in iter_motion (self .src , self .tb , stream , blur , width ):
295
295
if index > len (result ) - 1 :
296
296
result = np .concatenate (
297
- (result , np .zeros ((len (result )), dtype = np .float64 ))
297
+ (result , np .zeros ((len (result )), dtype = np .float32 ))
298
298
)
299
299
result [index ] = value
300
300
bar .tick (index )
0 commit comments