mirror of
https://gist.github.com/vivekhaldar/63764b085640bd82ebf07482f8a58cb8
synced 2024-09-28 14:54:27 +01:00
This commit is contained in:
parent
7fca9ce178
commit
94e2eb330a
@ -50,8 +50,8 @@ class Commands:
|
|||||||
'drop_segment': drop_segment,
|
'drop_segment': drop_segment,
|
||||||
'chapter_break': chapter_break,
|
'chapter_break': chapter_break,
|
||||||
}
|
}
|
||||||
input_file = 'input.mp4'
|
input_file = sys.argv[1]
|
||||||
output_file = 'output.mp4'
|
output_file = sys.argv[2]
|
||||||
def speech_to_text():
|
def speech_to_text():
|
||||||
model = whisper.load_model(MODEL)
|
model = whisper.load_model(MODEL)
|
||||||
modify_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
|
# 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.
|
# 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.
|
# Returns list of (start, end) tuples of intervals to keep.
|
||||||
def intervals_to_keep(commands):
|
def intervals_to_keep(commands):
|
||||||
@ -127,7 +128,7 @@ def intervals_to_keep(commands):
|
|||||||
match cmd:
|
match cmd:
|
||||||
case Commands.keep_segment:
|
case Commands.keep_segment:
|
||||||
# Keep until the start of the command.
|
# 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])
|
keep_intervals.append([keep_start, keep_end])
|
||||||
# Next (possibly) starts at end of command.
|
# Next (possibly) starts at end of command.
|
||||||
keep_start = end_ts
|
keep_start = end_ts
|
||||||
@ -187,9 +188,9 @@ def main():
|
|||||||
sts = speech_to_text()
|
sts = speech_to_text()
|
||||||
word_ts = word_level_timestamps(sts)
|
word_ts = word_level_timestamps(sts)
|
||||||
commands = find_commands(word_ts)
|
commands = find_commands(word_ts)
|
||||||
print(commands)
|
print(f'Commands: {commands}')
|
||||||
keep_intervals = intervals_to_keep(commands)
|
keep_intervals = intervals_to_keep(commands)
|
||||||
print(keep_intervals)
|
print(f'Keeping intervals: {keep_intervals}')
|
||||||
|
|
||||||
vid = VideoFileClip(input_file)
|
vid = VideoFileClip(input_file)
|
||||||
|
|
||||||
@ -202,6 +203,7 @@ def main():
|
|||||||
|
|
||||||
print("\n\n\n----- Writing out edited video... -----")
|
print("\n\n\n----- Writing out edited video... -----")
|
||||||
no_dead_air_video.write_videofile(output_file,
|
no_dead_air_video.write_videofile(output_file,
|
||||||
|
#edited_vid.write_videofile(output_file,
|
||||||
#fps=60,
|
#fps=60,
|
||||||
preset='ultrafast',
|
preset='ultrafast',
|
||||||
codec='libx264',
|
codec='libx264',
|
||||||
|
Loading…
Reference in New Issue
Block a user