From aa3a60823d6bb87a25c39a7213758a990b880bdd Mon Sep 17 00:00:00 2001 From: lixiang <32087152+lix8886@users.noreply.github.com> Date: Sun, 26 Apr 2026 01:53:18 +0800 Subject: [PATCH 1/5] add `etc` for hard encoding --- videocaptioner/core/utils/video_utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/videocaptioner/core/utils/video_utils.py b/videocaptioner/core/utils/video_utils.py index 2474a96f..d6b7255a 100644 --- a/videocaptioner/core/utils/video_utils.py +++ b/videocaptioner/core/utils/video_utils.py @@ -1,5 +1,6 @@ import os import re +import time import shutil import subprocess import tempfile @@ -311,6 +312,7 @@ def add_subtitles( # 实时Reading输出并调用回调函数 total_duration = None current_time = 0 + start_time = time.time() while True: output_line = process.stderr.readline() @@ -339,7 +341,14 @@ def add_subtitles( # 计算进度百分比 if total_duration: progress = (current_time / total_duration) * 100 - progress_callback(f"{round(progress)}", "正在合成") + etc = ( + (time.time() - start_time) + * (total_duration - current_time) + / current_time + ) + progress_callback( + f"{round(progress, 2)} | etc: {round(etc, 2)}秒", "正在合成" + ) if progress_callback: progress_callback("100", "合成完成") From c6a22d731d688682601836bbda4370bdb924b646 Mon Sep 17 00:00:00 2001 From: lixiang <32087152+lix8886@users.noreply.github.com> Date: Sun, 26 Apr 2026 02:28:10 +0800 Subject: [PATCH 2/5] add `etc` for hard encoding process --- videocaptioner/cli/output.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/videocaptioner/cli/output.py b/videocaptioner/cli/output.py index 8d990ba0..b07b092a 100644 --- a/videocaptioner/cli/output.py +++ b/videocaptioner/cli/output.py @@ -68,10 +68,22 @@ def start(self) -> "ProgressLine": self._thread.start() return self - def update(self, percent: int, message: str = "") -> None: + def update( + self, + percent: int, + message: str = "", + current_time: Optional[float] = None, + total_duration: Optional[float] = None, + ) -> None: self.percent = percent if message: self.message = message + if current_time is not None and total_duration is not None: + self._time_display = f" {format_time(current_time)} / {format_time(total_duration)}" + elif total_duration is not None: + self._time_display = f" / {format_time(total_duration)}" + else: + self._time_display = "" def _cleanup(self) -> None: self._stop.set() @@ -93,11 +105,26 @@ def fail(self, message: str = "") -> None: def _spin(self) -> None: while not self._stop.is_set(): char = self.SPINNER[self._frame % len(self.SPINNER)] + time_display = getattr(self, "_time_display", "") if self.percent is not None: line = f"\r{char} {self.message} [{self.percent}%]" + if time_display: + line += time_display else: line = f"\r{char} {self.message}" sys.stderr.write(f"{line}\033[K") sys.stderr.flush() self._frame += 1 self._stop.wait(0.1) + + +def format_time(seconds: float) -> str: + """Format seconds to MM:SS or HH:MM:SS format.""" + if seconds < 0: + seconds = 0 + hours = int(seconds // 3600) + minutes = int((seconds % 3600) // 60) + secs = int(seconds % 60) + if hours > 0: + return f"{hours}:{minutes:02d}:{secs:02d}" + return f"{minutes}:{secs:02d}" From 7b6c0542b8aacd032b9016726f00426dcf64fe10 Mon Sep 17 00:00:00 2001 From: lixiang <32087152+lix8886@users.noreply.github.com> Date: Sun, 26 Apr 2026 02:29:31 +0800 Subject: [PATCH 3/5] add `etc` for hard encoding process Removed time tracking for process duration in video processing. --- videocaptioner/core/utils/video_utils.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/videocaptioner/core/utils/video_utils.py b/videocaptioner/core/utils/video_utils.py index d6b7255a..2f373156 100644 --- a/videocaptioner/core/utils/video_utils.py +++ b/videocaptioner/core/utils/video_utils.py @@ -1,6 +1,5 @@ import os import re -import time import shutil import subprocess import tempfile @@ -312,7 +311,6 @@ def add_subtitles( # 实时Reading输出并调用回调函数 total_duration = None current_time = 0 - start_time = time.time() while True: output_line = process.stderr.readline() @@ -341,13 +339,8 @@ def add_subtitles( # 计算进度百分比 if total_duration: progress = (current_time / total_duration) * 100 - etc = ( - (time.time() - start_time) - * (total_duration - current_time) - / current_time - ) progress_callback( - f"{round(progress, 2)} | etc: {round(etc, 2)}秒", "正在合成" + f"{round(progress)}", "正在合成", current_time, total_duration ) if progress_callback: From 7690a49c30a6d584614c674c169f93626404700c Mon Sep 17 00:00:00 2001 From: lixiang <32087152+lix8886@users.noreply.github.com> Date: Sun, 26 Apr 2026 02:30:07 +0800 Subject: [PATCH 4/5] add `etc` for hard encoding process --- videocaptioner/cli/commands/synthesize.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/videocaptioner/cli/commands/synthesize.py b/videocaptioner/cli/commands/synthesize.py index 57436f28..14042292 100644 --- a/videocaptioner/cli/commands/synthesize.py +++ b/videocaptioner/cli/commands/synthesize.py @@ -198,7 +198,11 @@ def run(args: Namespace, config: dict) -> int: def progress_callback(*cb_args) -> None: if progress and cb_args: try: - progress.update(int(float(cb_args[0])), f"Encoding [{subtitle_mode}]") + percent = int(float(cb_args[0])) + message = cb_args[1] if len(cb_args) > 1 else "" + current_time = cb_args[2] if len(cb_args) > 2 else None + total_duration = cb_args[3] if len(cb_args) > 3 else None + progress.update(percent, message, current_time, total_duration) except (ValueError, TypeError): pass From 763ffb35882c34bf02e7f8232376d46eb578984b Mon Sep 17 00:00:00 2001 From: lixiang <32087152+lix8886@users.noreply.github.com> Date: Sun, 26 Apr 2026 02:31:24 +0800 Subject: [PATCH 5/5] Update progress callback with additional parameters Enhance progress callback to include current time and total duration. --- videocaptioner/core/subtitle/ass_renderer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/videocaptioner/core/subtitle/ass_renderer.py b/videocaptioner/core/subtitle/ass_renderer.py index b023acbd..79da6d26 100644 --- a/videocaptioner/core/subtitle/ass_renderer.py +++ b/videocaptioner/core/subtitle/ass_renderer.py @@ -386,7 +386,7 @@ def render_ass_video( # 计算进度百分比 if total_duration: progress = (current_time / total_duration) * 100 - progress_callback(f"{round(progress)}", "正在合成") + progress_callback(f"{round(progress)}", "正在合成", current_time, total_duration) if progress_callback: progress_callback("100", "合成完成")