This commit is contained in:
Vivek Haldar 2022-11-20 19:29:03 -08:00 committed by GitHub
parent 7fca9ce178
commit 94e2eb330a

View File

@ -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',