Skip to content

detect-adaptive --frame-window and save-images -n/-s/-H/-W crash with a traceback on out of range values #609

Closed

Description

@EnesSoydan

Description

Some options take any integer or number, and a value outside what the code accepts ends in a Python traceback instead of a usage error. This is the same problem #604 fixed for -k/--kernel-size, for these options:

Option Value Result
detect-adaptive -f/--frame-window 0, -3 ValueError: window_width must be at least 1.
save-images -n/--num-images 0, -1 ValueError: num_images must be greater than 0
save-images -s/--scale -1 cv2.error from cv2.resize
save-images -H/--height, -W/--width -5 AssertionError

The config file has the same problem: frame-window = 0 under [detect-adaptive] or num-images = 0 under [save-images] loads without an error and then crashes the same way. These keys are plain values in CONFIG_MAP, while similar options (min-images, max-images, compression) use RangeValue and _click_range.

Command

scenedetect -i tests/resources/goldeneye.mp4 time -e 1 detect-adaptive -f 0
scenedetect -i tests/resources/goldeneye.mp4 time -e 1 detect-content save-images -n 0

Output

  File ".../scenedetect/detectors/adaptive_detector.py", line 70, in __init__
    raise ValueError("window_width must be at least 1.")
ValueError: window_width must be at least 1.

Expected a usage error, for example:

Error: Invalid value for '--frame-window' / '-f': 0 is not in the range x>=1.

Environment

main at 47f95bd, Windows 11, Python 3.10.

I have a fix that makes these keys RangeValues (frame-window and num-images >= 1, scale, height and width >= 0, since 0 already means "not set") and uses _click_range for the CLI options. Happy to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions