|
1 | 1 | import os |
2 | 2 | import tempfile |
3 | 3 | import numpy as np |
| 4 | +import av |
4 | 5 | from vision_agents.core.utils.utils import parse_instructions, Instructions |
| 6 | +from vision_agents.core.utils.video_utils import ensure_even_dimensions |
5 | 7 | from vision_agents.core.edge.types import PcmData |
6 | 8 |
|
7 | 9 |
|
@@ -441,5 +443,39 @@ def test_pcm_data_resample_av_array_shape_fix(self): |
441 | 443 | assert resampled.samples.ndim == 1 |
442 | 444 |
|
443 | 445 |
|
444 | | -# Shared fixtures for integration tests |
445 | | - |
| 446 | +class TestEnsureEvenDimensions: |
| 447 | + """Test suite for ensure_even_dimensions function.""" |
| 448 | + |
| 449 | + def test_even_dimensions_unchanged(self): |
| 450 | + """Test that frames with even dimensions pass through unchanged.""" |
| 451 | + # Create a frame with even dimensions (1920x1080) |
| 452 | + frame = av.VideoFrame(width=1920, height=1080, format="yuv420p") |
| 453 | + |
| 454 | + result = ensure_even_dimensions(frame) |
| 455 | + |
| 456 | + assert result.width == 1920 |
| 457 | + assert result.height == 1080 |
| 458 | + |
| 459 | + def test_both_dimensions_odd_cropped(self): |
| 460 | + """Test that frames with both odd dimensions are cropped.""" |
| 461 | + # Create a frame with both odd dimensions (1921x1081) |
| 462 | + frame = av.VideoFrame(width=1921, height=1081, format="yuv420p") |
| 463 | + |
| 464 | + result = ensure_even_dimensions(frame) |
| 465 | + |
| 466 | + assert result.width == 1920 # Cropped from 1921 |
| 467 | + assert result.height == 1080 # Cropped from 1081 |
| 468 | + |
| 469 | + def test_timing_information_preserved(self): |
| 470 | + """Test that pts and time_base are preserved after cropping.""" |
| 471 | + from fractions import Fraction |
| 472 | + |
| 473 | + # Create a frame with timing information |
| 474 | + frame = av.VideoFrame(width=1921, height=1081, format="yuv420p") |
| 475 | + frame.pts = 12345 |
| 476 | + frame.time_base = Fraction(1, 30) |
| 477 | + |
| 478 | + result = ensure_even_dimensions(frame) |
| 479 | + |
| 480 | + assert result.pts == 12345 |
| 481 | + assert result.time_base == Fraction(1, 30) |
0 commit comments