Skip to content

Commit

Permalink
Merge pull request #45 from lagmoellertim/pr-remove-short-intervals-f…
Browse files Browse the repository at this point in the history
…rom-start

Removes too short intervals at the beginning
  • Loading branch information
Tim-Luca Lagmöller authored Nov 1, 2020
2 parents c07de64 + 2a6b21f commit d6ad9b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions unsilence/lib/intervals/Intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ def __enlarge_audible_intervals(self, stretch_time):
is_end_interval=(i == len(self.__interval_list) - 1)
)

def remove_short_intervals_from_start(self, audible_speed=1, silent_speed=2):
"""
Removes Intervals from start that are shorter than 0.5 seconds after
speedup to avoid having a final output without an audio track
:param audible_speed: The speed at which the audible intervals get played back at (float)
:param silent_speed: The speed at which the silent intervals get played back at (float)
:return: The new, possibly shorter, Intervals object
"""
for i, interval in enumerate(self.__interval_list):
if interval.is_silent:
speed = silent_speed
else:
speed = audible_speed

if interval.duration / speed > 0.5:
return Intervals(self.__interval_list[i:])

raise Exception("No interval has a length over 0.5 seconds after speed changes! This is required.")

def copy(self):
"""
Creates a deep copy
Expand Down
5 changes: 5 additions & 0 deletions unsilence/lib/render_media/MediaRenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def render(self, input_file: Path, output_file: Path, intervals: Intervals, **kw
drop_corrupted_intervals=kwargs.get("drop_corrupted_intervals", False)
)

intervals = intervals.remove_short_intervals_from_start(
render_options.audible_speed,
render_options.silent_speed
)

video_temp_path = self.__temp_path / str(uuid.uuid4())
video_temp_path.mkdir(parents=True)

Expand Down

0 comments on commit d6ad9b8

Please sign in to comment.