improve usage

pull/6/head
florentin.luce 2024-05-28 14:49:28 +02:00
parent 940cd1100f
commit 61f6ec3896
2 changed files with 57 additions and 22 deletions

View File

@ -26,12 +26,14 @@ def launch_split(movie_strip, threshold, frame_start=None, frame_end=None):
fps = bpy.context.scene.render.fps fps = bpy.context.scene.render.fps
if frame_start is None: if frame_start is None:
frame_start = movie_strip.frame_final_start frame_start = 0
if frame_end is None: if frame_end is None:
frame_end = movie_strip.frame_final_end frame_end = movie_strip.frame_duration
frame_start -= movie_strip.frame_final_start frame_start = frame_start - movie_strip.frame_start
frame_end -= movie_strip.frame_final_start
#frame_start += movie_strip.frame_offset_start
#frame_end -= movie_strip.frame_offset_end
# Launch ffmpeg command to split # Launch ffmpeg command to split
ffmpeg_cmd = get_command(str(path), threshold, frame_start, frame_end, fps) ffmpeg_cmd = get_command(str(path), threshold, frame_start, frame_end, fps)

View File

@ -2,14 +2,15 @@ from os.path import expandvars, abspath
from pathlib import Path from pathlib import Path
import bpy import bpy
from bpy.types import Operator from bpy.types import Operator
from bpy.props import (BoolProperty, StringProperty, FloatProperty) from bpy.props import (BoolProperty, StringProperty, FloatProperty,
IntProperty, EnumProperty)
from vse_toolbox.sequencer_utils import (get_strips, rename_strips, set_channels, from vse_toolbox.sequencer_utils import (get_strips, rename_strips, set_channels,
get_channel_index, new_text_strip, get_strip_at, get_channel_name) get_channel_index, new_text_strip, get_strip_at, get_channel_name,
create_shot_strip)
from vse_toolbox import auto_splitter from vse_toolbox import auto_splitter
from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings
from vse_toolbox.sequencer_utils import create_shot_strip
from shutil import copy2 from shutil import copy2
@ -183,9 +184,21 @@ class VSETB_OT_auto_split(Operator):
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
threshold: FloatProperty(name="Threshold", default=0.6, min=0, max=1) threshold: FloatProperty(name="Threshold", default=0.6, min=0, max=1)
selected_only: BoolProperty(name="Selected Only", default=True) frame_first: IntProperty(name='Start Split')
frame_last: IntProperty(name='End Split')
movie_channel_name: EnumProperty(
items=lambda self, ctx: ((c.name, c.name, '') for c in ctx.scene.sequence_editor.channels),
name='Movie Channel')
def invoke(self, context, event): def invoke(self, context, event):
self.frame_first = context.scene.frame_start
self.frame_last = context.scene.frame_end
if context.selected_sequences:
self.frame_first = min([s.frame_final_start for s in context.selected_sequences])
self.frame_last = max([s.frame_final_end for s in context.selected_sequences])
return context.window_manager.invoke_props_dialog(self) return context.window_manager.invoke_props_dialog(self)
def draw(self, context): def draw(self, context):
@ -196,6 +209,12 @@ class VSETB_OT_auto_split(Operator):
col.use_property_decorate = False col.use_property_decorate = False
col.prop(self, 'threshold') col.prop(self, 'threshold')
col.prop(self, 'movie_channel_name')
split_col = col.column(align=True)
split_col.prop(self, 'frame_first', text='Frame Split First')
split_col.prop(self, 'frame_last', text='Last')
col.prop(self, 'selected_only') col.prop(self, 'selected_only')
def execute(self, context): def execute(self, context):
@ -203,29 +222,42 @@ class VSETB_OT_auto_split(Operator):
return {'PASS_THROUGH'} return {'PASS_THROUGH'}
def modal(self, context, event): def modal(self, context, event):
strips = get_strips('Movie')
if self.selected_only: strips = get_strips(channel=self.movie_channel_name)
strips = context.selected_sequences
for strip in strips: for strip in strips:
if strip.type != 'MOVIE': if strip.type != 'MOVIE':
continue continue
process = auto_splitter.launch_split(strip, self.threshold) # Skip strip outside the frame range to create shot from.
if strip.frame_final_start >= self.frame_last or strip.frame_final_end <= self.frame_first:
continue
process = auto_splitter.launch_split(strip, self.threshold, frame_start=self.frame_first, frame_end=self.frame_last)
i = 1 i = 1
frame_start = 0 frame_start = self.frame_first
for line in process.stdout: for line in process.stdout:
# Get frame split from the movie timeline (not from blender strips timeline)
frame_end = auto_splitter.get_split_time(line, fps=24) frame_end = auto_splitter.get_split_time(line, fps=24)
if not frame_end: if not frame_end:
continue continue
# Convert movie frame to strips frame
if frame_start+int(strip.frame_start) < self.frame_first:
frame_start = self.frame_first
frame_end += int(strip.frame_final_start)
if frame_end > self.frame_last:
frame_end = self.frame_last
create_shot_strip( create_shot_strip(
f'tmp_shot_{str(i).zfill(3)}', f'tmp_shot_{str(i).zfill(3)}',
start=frame_start+strip.frame_final_start, start=frame_start,
end=frame_end+strip.frame_final_start end=frame_end
) )
i += 1 i += 1
@ -235,11 +267,12 @@ class VSETB_OT_auto_split(Operator):
process.wait() process.wait()
# last strip: # Last strip:
if frame_start < self.frame_last:
create_shot_strip( create_shot_strip(
f'tmp_shot_{str(i).zfill(3)}', f'tmp_shot_{str(i).zfill(3)}',
start=frame_start+strip.frame_final_start, start=frame_start,
end=strip.frame_final_end end=self.frame_last
) )
return {'FINISHED'} return {'FINISHED'}