use modal and display shots created one after other

This commit is contained in:
2024-05-27 14:40:23 +02:00
parent b1bde01b57
commit 940cd1100f
4 changed files with 133 additions and 40 deletions
+31 -17
View File
@@ -2,14 +2,14 @@ from os.path import expandvars, abspath
from pathlib import Path
import bpy
from bpy.types import Operator
from bpy.props import (BoolProperty, StringProperty, EnumProperty, FloatProperty)
from bpy.props import (BoolProperty, StringProperty, FloatProperty)
from vse_toolbox.sequencer_utils import (get_strips, rename_strips, set_channels,
get_channel_index, new_text_strip, get_strip_at, get_channel_name)
from vse_toolbox import auto_splitter
from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings
from vse_toolbox.auto_splitter import AutoSplitter
from vse_toolbox.constants import REVIEW_TEMPLATE_BLEND
from vse_toolbox.sequencer_utils import create_shot_strip
from shutil import copy2
@@ -199,8 +199,10 @@ class VSETB_OT_auto_split(Operator):
col.prop(self, 'selected_only')
def execute(self, context):
scn = context.scene
context.window_manager.modal_handler_add(self)
return {'PASS_THROUGH'}
def modal(self, context, event):
strips = get_strips('Movie')
if self.selected_only:
strips = context.selected_sequences
@@ -210,23 +212,35 @@ class VSETB_OT_auto_split(Operator):
if strip.type != 'MOVIE':
continue
splitter = AutoSplitter(bpy.path.abspath(strip.filepath))
splitter.launch_analysis(self.threshold)
process = auto_splitter.launch_split(strip, self.threshold)
split_frames = [0]
split_frames += splitter.get_split_times(as_frame=True)
i = 1
frame_start = 0
for line in process.stdout:
frame_end = auto_splitter.get_split_time(line, fps=24)
for i, frame in enumerate(split_frames):
if not frame_end:
continue
shot_strip = scn.sequence_editor.sequences.new_effect(
create_shot_strip(
f'tmp_shot_{str(i).zfill(3)}',
'COLOR',
get_channel_index('Shots'),
frame_start=frame + strip.frame_final_start,
frame_end=split_frames[i+1] + strip.frame_final_start if i+1 < len(split_frames) else strip.frame_final_end
start=frame_start+strip.frame_final_start,
end=frame_end+strip.frame_final_start
)
i += 1
frame_start = frame_end
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
process.wait()
# last strip:
create_shot_strip(
f'tmp_shot_{str(i).zfill(3)}',
start=frame_start+strip.frame_final_start,
end=strip.frame_final_end
)
shot_strip.blend_alpha = 0
shot_strip.color = (0.5, 0.5, 0.5)
return {'FINISHED'}