diff --git a/auto_splitter.py b/auto_splitter.py index 84da28b..63c5bc7 100644 --- a/auto_splitter.py +++ b/auto_splitter.py @@ -7,16 +7,16 @@ from vse_toolbox import file_utils class AutoSplitter(object): - def __init__(self, paths, fps=None): + def __init__(self, path, fps=None): - self.paths = paths + self.path = path self.fps = fps self.log_path = AUTO_SPLITTER_LOG def launch_analysis(self, threshold=0.6): - ffmpeg_cmd = f"ffmpeg -i {str(self.paths[0])} -filter:v \"select='gt(scene,{threshold})',showinfo\" -f null - 2> {str(self.log_path)}" + ffmpeg_cmd = f"ffmpeg -i {str(self.path)} -filter:v \"select='gt(scene,{threshold})',showinfo\" -f null - 2> {str(self.log_path)}" print(ffmpeg_cmd) subprocess.call(ffmpeg_cmd, shell=True) diff --git a/operators/sequencer.py b/operators/sequencer.py index b49f568..b582d52 100644 --- a/operators/sequencer.py +++ b/operators/sequencer.py @@ -200,30 +200,33 @@ class VSETB_OT_auto_split(Operator): def execute(self, context): scn = context.scene - first_frame = int(scn.frame_start) strips = get_strips('Movie') if self.selected_only: strips = context.selected_sequences - sources = list(set([bpy.path.abspath(strip.filepath) for strip in strips if strip.type == 'MOVIE'])) + for strip in strips: - splitter = AutoSplitter(sources) - splitter.launch_analysis(self.threshold) + if strip.type != 'MOVIE': + continue - split_frames = [0] - split_frames += splitter.get_split_times(as_frame=True) + splitter = AutoSplitter(bpy.path.abspath(strip.filepath)) + splitter.launch_analysis(self.threshold) - for i, frame in enumerate(split_frames): - strip = scn.sequence_editor.sequences.new_effect( - f'tmp_shot_{str(i).zfill(3)}', - 'COLOR', - get_channel_index('Shots'), - frame_start=frame + first_frame, - frame_end=split_frames[i+1] + first_frame if i < len(split_frames) else strips[0].frame_final_end - ) - strip.blend_alpha = 0 - strip.color = (0.5, 0.5, 0.5) + split_frames = [0] + split_frames += splitter.get_split_times(as_frame=True) + + for i, frame in enumerate(split_frames): + + shot_strip = scn.sequence_editor.sequences.new_effect( + 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 + ) + shot_strip.blend_alpha = 0 + shot_strip.color = (0.5, 0.5, 0.5) return {'FINISHED'}