From aa9e7121d9e08b3cad5ee3507bbb4231d1d6e727 Mon Sep 17 00:00:00 2001 From: lagmoellertim Date: Sat, 31 Oct 2020 02:40:13 +0100 Subject: [PATCH 1/2] Removes too short intervals at the beginning --- unsilence/__main__.py | 3 +++ unsilence/lib/intervals/Intervals.py | 19 +++++++++++++++++++ unsilence/lib/render_media/MediaRenderer.py | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 unsilence/__main__.py diff --git a/unsilence/__main__.py b/unsilence/__main__.py new file mode 100644 index 0000000..bfbe0c4 --- /dev/null +++ b/unsilence/__main__.py @@ -0,0 +1,3 @@ +from unsilence.command_line.EntryPoint import main + +main() diff --git a/unsilence/lib/intervals/Intervals.py b/unsilence/lib/intervals/Intervals.py index 59d1d4a..1de379b 100644 --- a/unsilence/lib/intervals/Intervals.py +++ b/unsilence/lib/intervals/Intervals.py @@ -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 diff --git a/unsilence/lib/render_media/MediaRenderer.py b/unsilence/lib/render_media/MediaRenderer.py index f533c8d..6b3e808 100644 --- a/unsilence/lib/render_media/MediaRenderer.py +++ b/unsilence/lib/render_media/MediaRenderer.py @@ -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) From 2a6b21fc3f5c25f1b496ea1d9de89b90418356cb Mon Sep 17 00:00:00 2001 From: lagmoellertim Date: Sat, 31 Oct 2020 03:04:29 +0100 Subject: [PATCH 2/2] Remove file from other PR --- unsilence/__main__.py | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 unsilence/__main__.py diff --git a/unsilence/__main__.py b/unsilence/__main__.py deleted file mode 100644 index bfbe0c4..0000000 --- a/unsilence/__main__.py +++ /dev/null @@ -1,3 +0,0 @@ -from unsilence.command_line.EntryPoint import main - -main()