Skip to content

[bugfix] Check crop bounds as inclusive in detect_scenes (#623) - #624

Merged
Breakthrough merged 2 commits into
Breakthrough:mainfrom
goranai:fix/crop-boundary-warning
Nov 28, 2026
Merged

Breakthrough merged 2 commits into
Breakthrough:mainfrom
goranai:fix/crop-boundary-warning

Conversation

@goranai

@goranai goranai commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #623.

SceneManager.detect_scenes read the internal _crop, which is stored one past the end, and checked it as if the bounds were inclusive. A crop that ends on the last column or row, such as --crop 0 0 319 239 on a 320x240 video, logged "crop ends outside of video boundary" even though it is inside the frame.

The fix reads the public inclusive crop value instead. It clamps to frame_width - 1 and frame_height - 1.

Behavior changes:

  • A crop that ends on the last column or row no longer logs the false warning. A crop one pixel past the right or bottom edge still logs it.
  • The effective frame size used for the auto downscale factor is now exact. Before, it was 1 pixel larger in each direction for every crop. For a full frame crop it was width + 1.

Tests: added test_crop_boundary_warning (5 cases, 2 fail on main). pytest tests/test_scene_manager.py gives 15 passed and pytest tests/test_cli.py -k crop gives 2 passed (resources branch fetched). A fuzz of 880 random crops on five frame sizes, including 1x1 and 2x2, compared the error, the warning and the effective size with an inclusive-bounds oracle. Main had 513 mismatches and the fix has 0.

Validated with Claude Opus 5.5.

@goranai
goranai force-pushed the fix/crop-boundary-warning branch from 551646c to 7cf960c Compare November 25, 2026 03:11

@Breakthrough Breakthrough left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Need to address failing static checks.

@goranai

goranai commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Fixed in 87a450c. Pyright flagged two lines: self.crop is typed as optional, so I read self._crop and step back by one instead, and the test now uses cv2.VideoWriter.fourcc. ruff check, ruff format --check and pyright pass on these files locally. The two errors pyright still reports here are missing optional imports (moviepy, imageio_ffmpeg) in my environment.

@Breakthrough Breakthrough left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the PR!

@Breakthrough Breakthrough added this to the 0.7.4 milestone Nov 28, 2026
@Breakthrough
Breakthrough merged commit e3b64dd into Breakthrough:main Nov 28, 2026
23 checks passed
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.

Crop ends on the last pixel logs a false boundary warning

2 participants