Video
Video processing module.
This module provides classes for handling video files, managing playback speed, and extracting frames for analysis.
Classes:
Name | Description |
---|---|
LocalVideo |
Basic video file handler with frame extraction capabilities |
SimpleVideo |
Basic video player with simple frame controls |
VideoSpeedManager |
Advanced video processor with adaptive frame skipping |
LocalVideo
Local video file handler with frame extraction capabilities.
Attributes:
Name | Type | Description |
---|---|---|
_vidcap |
VideoCapture
|
OpenCV video capture object |
_output_colors |
int
|
Color scheme for output frames |
_num_colors |
int
|
Number of color channels |
_frame_size |
tuple
|
Forced frame size (width, height) |
_vid_id |
str
|
Video identifier |
Methods:
Name | Description |
---|---|
extract_next_frame |
Extract next frame from video |
get_count_frames |
Get total number of frames |
get_dim_frame |
Get frame dimensions |
get_fps |
Get frames per second |
get_id_vid |
Get video identifier |
get_time_from_num_frame |
Convert frame number to time in seconds |
get_num_frame_from_time |
Convert time to frame number |
set_num_frame |
Set current frame number |
set_frame_size |
Set frame dimensions |
close |
Release video capture resources |
Source code in apps/annotator/code/media/video.py
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 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 185 186 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 |
|
__init__(video_id, output_colors=COLOR_BGR, forced_frame_size=None, _testing_path=None)
Initialize video file handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
video_id
|
str
|
Identifier for the video file |
required |
output_colors
|
int
|
Color scheme for output frames |
COLOR_BGR
|
forced_frame_size
|
tuple or None
|
Force specific frame dimensions (width, height) |
None
|
_testing_path
|
str
|
Override path for testing |
None
|
Source code in apps/annotator/code/media/video.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
close()
Release video capture resources.
Source code in apps/annotator/code/media/video.py
110 111 112 113 114 |
|
extract_next_frame()
Extract next frame from video.
Returns:
Type | Description |
---|---|
ndarray or None
|
Image array if frame exists, None otherwise |
Source code in apps/annotator/code/media/video.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
get_count_frames()
Get total number of frames in video.
Returns:
Type | Description |
---|---|
int
|
Total frame count |
Source code in apps/annotator/code/media/video.py
134 135 136 137 138 139 140 141 142 143 |
|
get_dim_frame()
Get frame dimensions.
Returns:
Type | Description |
---|---|
tuple
|
(width, height, num_colors) |
Source code in apps/annotator/code/media/video.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
get_fps()
Get video frames per second.
Returns:
Type | Description |
---|---|
int
|
Frames per second |
Source code in apps/annotator/code/media/video.py
161 162 163 164 165 166 167 168 169 170 |
|
get_id_vid()
Get video identifier.
Returns:
Type | Description |
---|---|
str
|
Video ID |
Source code in apps/annotator/code/media/video.py
172 173 174 175 176 177 178 179 180 181 |
|
get_num_frame_from_time(seconds)
Convert time to frame number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seconds
|
float
|
Time in seconds |
required |
Returns:
Type | Description |
---|---|
int
|
Frame number |
Source code in apps/annotator/code/media/video.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
get_time_from_num_frame(num_frame, decimals=1)
Convert frame number to time in seconds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_frame
|
int
|
Frame number |
required |
decimals
|
int
|
Number of decimal places |
1
|
Returns:
Type | Description |
---|---|
float
|
Time in seconds |
Source code in apps/annotator/code/media/video.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
set_frame_size(value)
Set frame dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
tuple
|
New frame dimensions (width, height) |
required |
Source code in apps/annotator/code/media/video.py
228 229 230 231 232 233 234 235 236 237 |
|
set_num_frame(num_frame)
Set current frame number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_frame
|
int
|
Frame number to set |
required |
Source code in apps/annotator/code/media/video.py
217 218 219 220 221 222 223 224 225 226 |
|
SimpleVideo
Basic video player with simple frame controls.
Attributes:
Name | Type | Description |
---|---|---|
video |
VideoCapture
|
OpenCV video capture object |
_curr_step |
int
|
Current frame step size |
_curr_frame_idx |
int
|
Current frame index |
Methods:
Name | Description |
---|---|
close |
Release video resources |
get_count_frames |
Get total number of frames |
get_fps |
Get frames per second |
get_frame |
Get next frame based on step size |
roll |
Move frame position by offset |
rewind |
Return to start of video |
set_step |
Set frame step size |
get_frame_index |
Get current frame index |
Source code in apps/annotator/code/media/video.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
|
__init__(video_id)
Initialize simple video player.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
video_id
|
str
|
Identifier for the video file |
required |
Source code in apps/annotator/code/media/video.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
|
close()
Release video capture resources.
Source code in apps/annotator/code/media/video.py
661 662 663 664 665 |
|
get_count_frames()
Get total number of frames in video.
Returns:
Type | Description |
---|---|
int
|
Total frame count |
Source code in apps/annotator/code/media/video.py
667 668 669 670 671 672 673 674 675 676 |
|
get_fps()
Get video frames per second.
Returns:
Type | Description |
---|---|
int
|
Frames per second |
Source code in apps/annotator/code/media/video.py
678 679 680 681 682 683 684 685 686 687 |
|
get_frame()
Get next frame based on current step size.
Returns:
Type | Description |
---|---|
ndarray
|
Next video frame |
Source code in apps/annotator/code/media/video.py
689 690 691 692 693 694 695 696 697 698 699 700 |
|
get_frame_index(one_step_back=False)
Get current frame index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
one_step_back
|
bool
|
If True, returns index minus one step |
False
|
Returns:
Type | Description |
---|---|
int
|
Current frame index |
Source code in apps/annotator/code/media/video.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
|
rewind()
Return to first frame of video.
Source code in apps/annotator/code/media/video.py
714 715 716 717 718 |
|
roll(offset)
Move frame position by given offset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset
|
int
|
Number of frames to move (positive or negative) |
required |
Source code in apps/annotator/code/media/video.py
702 703 704 705 706 707 708 709 710 711 712 |
|
set_step(step)
Set frame step size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step
|
int
|
Number of frames to skip between each get_frame call |
required |
Source code in apps/annotator/code/media/video.py
720 721 722 723 724 725 726 727 728 729 |
|
VideoSpeedManager
Advanced video processor with adaptive frame skipping.
This class implements an adaptation of TCP fast retransmit algorithm for smart frame sampling.
The principle is the following:
With exponential growth of the frame skip rate, the algorithm tries to skip many identical frames until a threshold where the growth becomes linear.
When a collision is detected (the text is changed with respect to the cached one), it rolls back to the first frame of that text occurrence and sets a linear growth of the frame skip rate. If no text is detected, the speed of skip will be exponential again.
Attributes:
Name | Type | Description |
---|---|---|
vid_ref |
LocalVideo
|
Reference to video file handler |
_color_scheme |
int
|
Color scheme for output frames |
_curr_num_frame |
int
|
Current frame number |
_is_video_ended |
bool
|
Flag indicating video end |
_is_forced_speed |
bool
|
Flag for forced speed mode |
Methods:
Name | Description |
---|---|
get_frame |
Get next frame based on current speed |
collide_and_get_fixed_num_frame |
Handle text detection collision |
lock_speed |
Lock frame skip rate |
Source code in apps/annotator/code/media/video.py
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 298 299 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
|
collide_and_get_fixed_num_frame()
Handle text detection collision by finding first frame with text.
Uses binary search to find the first frame where text appears between current position and last known position.
Returns:
Type | Description |
---|---|
int
|
Frame number where text first appears |
Source code in apps/annotator/code/media/video.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
|
end_collision()
Reset collision state and prepare for linear growth phase.
Sets internal flags to transition from collision handling to linear growth phase.
Source code in apps/annotator/code/media/video.py
521 522 523 524 525 526 527 528 529 530 531 |
|
get_following_frame()
Get next sequential frame.
Returns:
Type | Description |
---|---|
ndarray
|
Next frame in sequence |
Source code in apps/annotator/code/media/video.py
590 591 592 593 594 595 596 597 598 599 600 601 |
|
get_frame()
Get next frame based on current speed settings.
The frame skip rate adapts based on current phase: - Collision: minimum skip rate - Exponential: exponentially increasing skip - Linear: linearly increasing skip - Forced: fixed skip rate
Returns:
Type | Description |
---|---|
ndarray
|
Next video frame |
Source code in apps/annotator/code/media/video.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
|
get_frame_from_num(num_frame)
Get specific frame by number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_frame
|
int
|
Frame number to retrieve |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Requested video frame |
Source code in apps/annotator/code/media/video.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
get_percentage_progression()
Calculate video processing progress.
Returns:
Type | Description |
---|---|
int
|
Percentage of video processed (0-100) |
Source code in apps/annotator/code/media/video.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
get_video()
Get reference to video handler.
Returns:
Type | Description |
---|---|
LocalVideo
|
Reference to video handler object |
Source code in apps/annotator/code/media/video.py
348 349 350 351 352 353 354 355 356 357 |
|
lock_speed(num_frames_skipped=None)
Lock frame skip rate to fixed value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_frames_skipped
|
int or None
|
Number of frames to skip, uses minimum if None |
None
|
Source code in apps/annotator/code/media/video.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
|
rewind_to(num_frame)
Rewind video to specific frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_frame
|
int
|
Target frame number |
required |
Source code in apps/annotator/code/media/video.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
|
set_analysis_frames(frames)
Set specific frame ranges for analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frames
|
list of tuple
|
List of (start_frame, end_frame) ranges |
required |
Source code in apps/annotator/code/media/video.py
603 604 605 606 607 608 609 610 611 612 |
|