Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Remixer: Updates to Find Break feature #341

Merged
merged 5 commits into from
Oct 9, 2024
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
70 changes: 52 additions & 18 deletions tabs/video_remixer_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ def render_tab(self):
goto_50_702 = gr.Button(value="Middle", scale=1, min_width=90, size="sm")
goto_100_702 = gr.Button(value="Last >", scale=1, min_width=90, size="sm")
next_minute_702 = gr.Button(value="Minute >", scale=1, min_width=90, size="sm")
with gr.Row():
prev_keep_702 = gr.Button(value="< Prev Keep", size="sm", variant="primary")
next_keep_702 = gr.Button(value="Next Keep >", size="sm", variant="primary")
prev_break_702 = gr.Button(value="< Prev Break" + SimpleIcons.SLOW_SYMBOL, size="sm", variant="primary")
next_break_702 = gr.Button(value="Next Break" + SimpleIcons.SLOW_SYMBOL + " >", size="sm", variant="primary")
with gr.Row():
with gr.Column(scale=1):
with gr.Row(equal_height=True, variant="panel", elem_id="highlightbutton"):
Expand All @@ -612,9 +617,6 @@ def render_tab(self):
label="Secondary Split Position", minimum=0.0,
maximum=100.0, step=0.1, container=False, scale=2,
info="Earliest split is performed first")
with gr.Row(variant="compact", equal_height=False):
prev_break_702 = gr.Button(value="< Find Break Frame" + SimpleIcons.SLOW_SYMBOL, size="sm")
next_break_702 = gr.Button(value="Find Break Frame" + SimpleIcons.SLOW_SYMBOL + " >", size="sm")
with gr.Row(variant="compact", equal_height=False):
set_view_hint_702 = gr.Textbox(placeholder="View Hint such as {V:200%}",
max_lines=1, show_label=False,
Expand Down Expand Up @@ -1375,9 +1377,20 @@ def render_tab(self):
outputs=[split_percent_702, split_percent_alt_702],
show_progress=False)

prev_keep_702.click(self.prev_keep_702,
inputs=[scene_id_702, split_percent_702],
outputs=[scene_id_702, preview_image702, scene_info_702],
show_progress=True)

next_keep_702.click(self.next_keep_702,
inputs=[scene_id_702, split_percent_702],
outputs=[scene_id_702, preview_image702, scene_info_702],
show_progress=True)

prev_break_702.click(self.prev_break_702,
inputs=[scene_id_702, split_percent_702],
outputs=split_percent_702, show_progress=True)

next_break_702.click(self.next_break_702,
inputs=[scene_id_702, split_percent_702],
outputs=split_percent_702, show_progress=True)
Expand Down Expand Up @@ -2747,7 +2760,10 @@ def find_break_frame_type(self, frame_file) -> Literal["break", "skip", "find"]:
else:
break_type = "find"

return break_type
return break_type, l

def compute_split_from_frame(self, frame_index, num_frames):
return 100.0 * (frame_index * 1.0 / num_frames)

def next_break_702(self, scene_index, split_percent):
scene_index = int(scene_index)
Expand All @@ -2765,34 +2781,38 @@ def next_break_702(self, scene_index, split_percent):
return split_percent
starting_search_frame = split_frame + 1
search_frame_index : int = starting_search_frame
fallback_found_frame = split_frame
fallback_value = 256

frame_files = self.state.get_split_scene_cache(scene_index)

frame_file = frame_files[search_frame_index]
frame_type = self.find_break_frame_type(frame_file)
frame_type, value = self.find_break_frame_type(frame_file)
if frame_type == "skip":
# skip frames until either a break frame or a find frame
for search_frame_index in range(search_frame_index + 1, last_frame + 1):
frame_file = frame_files[search_frame_index]
frame_type = self.find_break_frame_type(frame_file)
frame_type, value = self.find_break_frame_type(frame_file)
if frame_type == "break" or frame_type == "find":
break

if search_frame_index > last_starting_search_frame:
return split_percent
return self.compute_split_from_frame(fallback_found_frame, num_frames)

if frame_type != "break":
for search_frame_index in range(search_frame_index + 1, last_frame + 1):
frame_file = frame_files[search_frame_index]
frame_type = self.find_break_frame_type(frame_file)
frame_type, value = self.find_break_frame_type(frame_file)
if value < fallback_value:
fallback_found_frame = search_frame_index
fallback_value = value
if frame_type == "break":
break

if frame_type == "break": # and search_frame_index != starting_search_frame:
new_split_percent = 100.0 * (search_frame_index * 1.0 / num_frames)
return new_split_percent
return self.compute_split_from_frame(search_frame_index, num_frames)

return split_percent
return self.compute_split_from_frame(fallback_found_frame, num_frames)

def prev_break_702(self, scene_index, split_percent):
scene_index = int(scene_index)
Expand All @@ -2810,34 +2830,48 @@ def prev_break_702(self, scene_index, split_percent):
return split_percent
starting_search_frame = split_frame - 2 # split frame is after the split, now going in rev.
search_frame_index : int = starting_search_frame
fallback_found_frame = split_frame
fallback_value = 256

frame_files = self.state.get_split_scene_cache(scene_index)

frame_file = frame_files[starting_search_frame]
frame_type = self.find_break_frame_type(frame_file)
frame_type, value = self.find_break_frame_type(frame_file)
if frame_type == "skip":
# skip frames until either a break frame or a find frame
for search_frame_index in range(search_frame_index - 1, last_frame - 1, -1):
frame_file = frame_files[search_frame_index]
frame_type = self.find_break_frame_type(frame_file)
frame_type, value = self.find_break_frame_type(frame_file)
if frame_type == "break" or frame_type == "find":
break

if search_frame_index < last_starting_search_frame:
return split_percent
return self.compute_split_from_frame(fallback_found_frame, num_frames)

if frame_type != "break":
for search_frame_index in range(search_frame_index - 1, last_frame - 1, -1):
frame_file = frame_files[search_frame_index]
frame_type = self.find_break_frame_type(frame_file)
frame_type, value = self.find_break_frame_type(frame_file)
if value < fallback_value:
fallback_found_frame = search_frame_index
fallback_value = value
if frame_type == "break":
break

if frame_type == "break":
new_split_percent = 100.0 * (search_frame_index * 1.0 / num_frames)
return new_split_percent
return self.compute_split_from_frame(search_frame_index, num_frames)

return self.compute_split_from_frame(fallback_found_frame, num_frames)

return split_percent
def prev_keep_702(self, scene_index, split_percent):
scene_index = int(scene_index)
scene_index, _, _, _, _, _ = self.scan_for_keep(range(scene_index-1, -1, -1))
return scene_index, *self.update_preview(scene_index, split_percent)

def next_keep_702(self, scene_index, split_percent):
scene_index = int(scene_index)
scene_index, _, _, _, _, _ = self.scan_for_keep(range(scene_index+1, len(self.state.scene_names)))
return scene_index, *self.update_preview(scene_index, split_percent)

def back_button702(self):
return gr.update(selected=self.TAB_CHOOSE_SCENES)
Expand Down
Loading