From 94e2eb330aff39eae719fdcfe56271dfe60ee0e7 Mon Sep 17 00:00:00 2001 From: Vivek Haldar Date: Sun, 20 Nov 2022 19:29:03 -0800 Subject: [PATCH] --- whisper_edit.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/whisper_edit.py b/whisper_edit.py index f16f0e5..1f0d16d 100644 --- a/whisper_edit.py +++ b/whisper_edit.py @@ -50,8 +50,8 @@ class Commands: 'drop_segment': drop_segment, 'chapter_break': chapter_break, } -input_file = 'input.mp4' -output_file = 'output.mp4' +input_file = sys.argv[1] +output_file = sys.argv[2] def speech_to_text(): model = whisper.load_model(MODEL) modify_model(model) @@ -116,7 +116,8 @@ def find_commands(timestamps): # Hack. When dropping a segment I see a split-second of the end of # the dropped segment. So add a small fuzz factor for that. -DROP_SEGMENT_DELTA = 0.2 +DROP_SEGMENT_DELTA = 0.0 +KEEP_SEGMENT_DELTA = 0.8 # Returns list of (start, end) tuples of intervals to keep. def intervals_to_keep(commands): @@ -127,7 +128,7 @@ def intervals_to_keep(commands): match cmd: case Commands.keep_segment: # Keep until the start of the command. - keep_end = begin_ts + keep_end = begin_ts - KEEP_SEGMENT_DELTA keep_intervals.append([keep_start, keep_end]) # Next (possibly) starts at end of command. keep_start = end_ts @@ -187,9 +188,9 @@ def main(): sts = speech_to_text() word_ts = word_level_timestamps(sts) commands = find_commands(word_ts) - print(commands) + print(f'Commands: {commands}') keep_intervals = intervals_to_keep(commands) - print(keep_intervals) + print(f'Keeping intervals: {keep_intervals}') vid = VideoFileClip(input_file) @@ -202,6 +203,7 @@ def main(): print("\n\n\n----- Writing out edited video... -----") no_dead_air_video.write_videofile(output_file, + #edited_vid.write_videofile(output_file, #fps=60, preset='ultrafast', codec='libx264',