Skip to content

Fix cropping window stalling on repeated use in the same session#331

Merged
alexarje merged 2 commits into
masterfrom
copilot/fix-cropping-function-issue
Apr 13, 2026
Merged

Fix cropping window stalling on repeated use in the same session#331
alexarje merged 2 commits into
masterfrom
copilot/fix-cropping-function-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

On Linux, cv2.imshow/cv2.waitKey must run on the main thread. The manual crop UI was invoked via threading.Thread, which worked on the first call but left OpenCV's GUI subsystem in a broken state — causing every subsequent crop call in the same session to stall indefinitely.

Changes

  • musicalgestures/_cropvideo.py: Replace threading.Thread with subprocess.run(sys.executable, '_cropping_window.py', ...) in mg_cropvideo_ffmpeg. Each crop invocation now runs in a fresh, isolated process — which is what _cropping_window.py was already designed for (it accepts CLI args and prints w h x y to stdout).
    • Restore the previously commented-out first-frame extraction logic (get_first_frame_as_image, get_box_video_ratio) needed to feed the subprocess.
    • Add subprocess return-code check with stderr in the error message.
    • Add output validation (exactly 4 integers expected) before unpacking.
    • Clean up the temp frame image after subprocess exits.
# Before — threading caused OpenCV GUI state corruption after first use
t = threading.Thread(target=lambda q, arg1: q.put(cropping_window(arg1)), args=(que, filename))
t.start()
t.join()

# After — fresh subprocess per call, no shared GUI state
result = subprocess.run(
    [sys.executable, pyfile, first_frame_as_image, str(scale_ratio), str(scaled_width), str(scaled_height)],
    stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)

Copilot AI linked an issue Apr 13, 2026 that may be closed by this pull request
…tall on repeated use on Linux

Agent-Logs-Url: https://github.com/fourMs/MGT-python/sessions/682682bd-1b41-4253-bae7-913f4e0d8fa8

Co-authored-by: alexarje <114316+alexarje@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cropping function to work multiple times Fix cropping window stalling on repeated use in the same session Apr 13, 2026
Copilot AI requested a review from alexarje April 13, 2026 15:38
@alexarje alexarje marked this pull request as ready for review April 13, 2026 16:05
@alexarje alexarje merged commit a9fbd44 into master Apr 13, 2026
2 of 11 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.

Cropping only works once

2 participants