Video sampler
EntropyByffer
Bases: FrameBuffer
Measure image entropy as a function of the image usability
Source code in video_sampler/buffer.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
FrameBuffer
Bases: ABC
Source code in video_sampler/buffer.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
clear()
abstractmethod
Clear the buffer
Source code in video_sampler/buffer.py
94 95 96 97 |
|
final_flush()
abstractmethod
Flush the buffer and return the remaining items
Source code in video_sampler/buffer.py
84 85 86 87 |
|
get_buffer_state()
abstractmethod
Return the current state of the buffer
Source code in video_sampler/buffer.py
89 90 91 92 |
|
GridBuffer
Bases: HashBuffer
A class representing a grid-based buffer for images. Splits the image into a grid and stores the hashes of the grid cells in a mosaic buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
The maximum size of the buffer. |
required |
debug_flag |
bool
|
A flag indicating whether debug information should be printed. |
False
|
hash_size |
int
|
The size of the hash. |
4
|
grid_x |
int
|
The number of grid cells in the x-axis. |
4
|
grid_y |
int
|
The number of grid cells in the y-axis. |
4
|
max_hits |
int
|
The maximum number of hits allowed for a hash. |
1
|
Attributes:
Name | Type | Description |
---|---|---|
grid_x |
int
|
The number of grid cells in the x-axis. |
grid_y |
int
|
The number of grid cells in the y-axis. |
max_hits |
int
|
The maximum number of hits allowed for a hash. |
mosaic_buffer |
dict
|
A dictionary storing the mosaic buffer. |
Methods:
Name | Description |
---|---|
add |
Adds an image to the buffer along with its metadata. |
clear |
Clears the buffer and the mosaic buffer. |
update_ttl_buffer |
Updates the buffer by expiring images that are not in the grid. |
Source code in video_sampler/buffer.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
__get_grid_hash(item)
Compute grid hashes for a given image
Source code in video_sampler/buffer.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
GzipBuffer
Bases: FrameBuffer
Measure compression size as a function of the image usability
Source code in video_sampler/buffer.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
HashBuffer
Bases: FrameBuffer
A buffer that stores frames with their corresponding metadata and checks for duplicates based on image hashes. Args: size (int): The maximum size of the buffer. debug_flag (bool, optional): Flag indicating whether to enable debug mode. Defaults to False. hash_size (int, optional): The size of the image hash. Defaults to 4.
Methods:
Name | Description |
---|---|
get_buffer_state |
Returns the current state of the buffer as a list of image hashes. |
add |
Image.Image, metadata: dict[str, Any]) Adds an item to the buffer along with its metadata. |
final_flush |
Yields the stored items and their metadata in the buffer. |
Private Methods
__add(item: Image.Image, hash_: str, metadata: dict) Adds an item to the buffer with the given hash and metadata.
__check_duplicate(hash_: str) -> bool: Checks if the given hash already exists in the buffer and renews its validity if found.
Source code in video_sampler/buffer.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
SamplerConfig
Bases: BaseModel
Configuration options for the video sampler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_frame_interval_sec |
float
|
The minimum time interval between sampled frames in seconds. Defaults to 1. |
required |
keyframes_only |
bool
|
Flag indicating whether to sample only keyframes. Defaults to True. |
required |
queue_wait |
float
|
The time to wait between checking the frame queue in seconds. Defaults to 0.1. |
required |
debug |
bool
|
Flag indicating whether to enable debug mode. Defaults to False. |
required |
print_stats |
bool
|
Flag indicating whether to print sampling statistics. Defaults to False. |
required |
buffer_config |
dict[str, Any]
|
Configuration options for the frame buffer. Defaults to {"type": "entropy", "size": 15, "debug": True}. |
required |
gate_config |
dict[str, Any]
|
Configuration options for the frame gate. Defaults to {"type": "pass"}. |
required |
extractor_config |
dict[str, Any]
|
Configuration options for the extractor (keyword, audio). Defaults to None. |
required |
summary_config |
dict[str, Any]
|
Configuration options for the summary generator. Defaults to None. |
required |
Methods: str() -> str: Returns a string representation of the configuration.
Source code in video_sampler/buffer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
SlidingTopKBuffer
Bases: FrameBuffer
A class representing a sliding top-k buffer for frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
The maximum size of the buffer. |
required |
debug_flag |
bool
|
A flag indicating whether debug information should be printed. |
False
|
expiry |
int
|
The expiry count for frames. |
30
|
hash_size |
int
|
The size of the hash. |
8
|
Attributes:
Name | Type | Description |
---|---|---|
sliding_buffer |
list
|
The sliding buffer implemented as a min heap. |
max_size |
int
|
The maximum size of the buffer. |
debug_flag |
bool
|
A flag indicating whether debug information should be printed. |
expiry_count |
int
|
The expiry count for frames. |
hash_size |
int
|
The size of the hash. |
Methods:
Name | Description |
---|---|
get_buffer_state |
Returns the current state of the buffer. |
add |
Adds a frame to the buffer along with its metadata. |
final_flush |
Performs a final flush of the buffer and yields the remaining frames. |
clear |
Clears the buffer. |
Source code in video_sampler/buffer.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
create_buffer(buffer_config)
Create a buffer based on the config
Source code in video_sampler/buffer.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
|