Skip to content

Write resized video frames into final output#33

Merged
bghira merged 2 commits into
mainfrom
agent/direct-video-resize-output
Jul 17, 2026
Merged

Write resized video frames into final output#33
bghira merged 2 commits into
mainfrom
agent/direct-video-resize-output

Conversation

@bghira

@bghira bghira commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • allocate each resized video result once
  • point OpenCV destination Mat headers directly at each final output frame
  • eliminate temporary resized frame ndarrays and reconstruction copies
  • preserve support for videos with a strided frame axis when each frame remains contiguous

Root cause

The video path flattened all frames, used the copy-heavy image API to create one ndarray per resized frame, then allocated each output video and copied every frame into it again. The memory traffic and allocation overhead dominated resize time.

Performance

Median local latency on Apple M3 Max:

  • 30x1024x1024 -> 30x512x512: 11.50 ms -> 1.57 ms
  • 120x512x512 -> 120x224x224: 7.72 ms -> 2.48 ms

The direct path also beat resizing through batch_resize_images_zero_copy followed by numpy.stack (3.37 ms and 3.07 ms respectively).

Validation

  • cargo test --features opencv,simd (60 passed)
  • Python test suite (68 passed)
  • repository pre-commit hooks, including competitive performance benchmarks

@bghira
bghira marked this pull request as ready for review July 17, 2026 15:38
@bghira
bghira requested a review from Copilot July 17, 2026 15:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the Rust/OpenCV video resize path by allocating each output video once and having OpenCV write resized frames directly into the final output buffer, reducing per-frame allocations and extra copies.

Changes:

  • Replace the “flatten all frames then reconstruct” approach with per-video output allocation and direct frame writes.
  • Create OpenCV Mat headers that point directly into the destination ndarray::Array4 frame buffers.
  • Keep support for strided frame-axis inputs as long as each individual frame is contiguous.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/opencv_ops.rs
@bghira
bghira merged commit 169e0f8 into main Jul 17, 2026
10 checks passed
@bghira
bghira deleted the agent/direct-video-resize-output branch July 17, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants