Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions musicalgestures/_cropvideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,37 @@ def mg_cropvideo_ffmpeg(

if crop_movement.lower() == 'manual':
if not in_colab():

# scale_ratio = get_box_video_ratio(filename)
# width, height = get_widthheight(filename)
# scaled_width, scaled_height = [int(elem * scale_ratio) for elem in [width, height]]
# first_frame_as_image = get_first_frame_as_image(filename, pict_format='.jpg')

# Cropping UI moved to another subprocess to avoid cv2.waitKey crashing Python with segmentation fault on Linux in Terminal
import threading
import queue

que = queue.Queue()
t = threading.Thread(target=lambda q, arg1:q.put(cropping_window(arg1)), args=(que, filename))

t.start()
t.join()

w, h, x, y = que.get()

# x = threading.Thread(target=run_cropping_window, args=(first_frame_as_image, scale_ratio, scaled_width, scaled_height))
# run_cropping_window(first_frame_as_image, scale_ratio, scaled_width, scaled_height)
# x.start()
# x.join()
import sys
import subprocess
import musicalgestures

scale_ratio = get_box_video_ratio(filename)
width, height = get_widthheight(filename)
scaled_width, scaled_height = [int(elem * scale_ratio) for elem in [width, height]]
first_frame_as_image = get_first_frame_as_image(filename, pict_format='.jpg')

module_path = os.path.abspath(os.path.dirname(musicalgestures.__file__))
pyfile = os.path.join(module_path, '_cropping_window.py')

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
)

os.remove(first_frame_as_image)

if result.returncode != 0:
raise RuntimeError(
f"Cropping window subprocess failed (exit code {result.returncode}):\n{result.stderr}"
)

res = result.stdout.strip()
res_array = res.split(' ')
if len(res_array) != 4:
raise RuntimeError(
f"Unexpected output from cropping window: '{res}'"
)
w, h, x, y = [int(elem) for elem in res_array]

else:
x, y, w, h = manual_text_input()
Expand All @@ -228,11 +237,6 @@ def mg_cropvideo_ffmpeg(

cropped_video = crop_ffmpeg(filename, w, h, x, y, target_name=target_name, overwrite=overwrite)

# if crop_movement.lower() == 'manual':
# cv2.destroyAllWindows()
# if not in_colab():
# os.remove(first_frame_as_image)

return cropped_video


Expand Down
Loading