Commit d97593a
authored
test(multimodal): content-preservation tests for video frame extraction
* test(multimodal): content-preservation tests for video frame extraction
Add four pixel-level content-preservation tests that catch bugs the existing shape-only tests cannot: wrong color channel order (BGR vs RGB), wrong sample timing (off-by-one in frame indexing), and frame content corruption.
In src/multimodal/video_tests.rs:
- synth_color_increment_video: helper that writes per-frame solid-color PNGs using the image crate and encodes to MP4 via ffmpeg. Frame i has color (5*i, 4*i, 3*i) clamped to 255 so all three channels vary independently.
- synth_moving_square_video: helper that renders an 8x8 white square on black, moving diagonally one pixel per frame, so the square's position encodes the source frame index.
- extract_frames_preserves_color_increment_per_frame: synthesizes a 50-frame / 10-fps color-increment video, samples 25 frames, and asserts each frame's per-channel mean matches the expected color within ±15 counts (YUV420 chroma subsampling + H.264 codec rounding).
- extract_frames_preserves_channel_order: synthesizes a solid R=200/G=100/B=50 video, loads 2 frames, and checks center-pixel channel layout via to_rgb8 within ±15 counts.
- extract_frames_preserves_moving_square_position: synthesizes the moving-square video, samples all 20 frames, and asserts the brightest pixel cluster falls in the expected 8x8 window for each frame (±4px slack for H.264 DCT blocking artifacts).
In src/vision/processors/gemma4_tests.rs:
- process_videos_pixel_values_match_input_color: full-pipeline test that synthesizes a solid-color video, runs load_video → Gemma4Processor::process_videos, extracts NCHW tensor bytes via mlxcel_core::eval + array_to_raw_bytes, and asserts per-channel mean (after de-normalization ×255) matches the input color within ±20 counts. Catches BGR packing errors in the NCHW layout.
All new tests are gated with the existing ffmpeg_available pattern and skip gracefully (no panic) when ffmpeg is absent. No checked-in video binaries are introduced. The 27 + 11 pre-existing tests continue to pass.
* chore: apply cargo fmt to content-preservation test files
Reformats line wrapping in video_tests.rs and gemma4_tests.rs to match rustfmt's preferred style (argument lists, assert! calls, let bindings). No logic changes.1 parent c9ff8c6 commit d97593a
2 files changed
Lines changed: 607 additions & 1 deletion
0 commit comments