From a0b37e015dcfd7585101aa8222a002811dd8aeb4 Mon Sep 17 00:00:00 2001 From: Jerry <792602257@qq.com> Date: Tue, 19 Mar 2024 13:58:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E6=A3=80=E6=9F=A5=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=80=BB=E9=95=BF=E5=BA=A6=E3=80=82=E5=9B=A0=E4=B8=BA=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=84=8F=E4=B9=89=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- danmaku_workflow.py | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/danmaku_workflow.py b/danmaku_workflow.py index 1a398ba..e6c5ec8 100644 --- a/danmaku_workflow.py +++ b/danmaku_workflow.py @@ -267,7 +267,7 @@ class WorkerThread(QThread): ffmpeg_process = subprocess.Popen([ FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-i", filename, "-c", "copy", "-f", "null", "-" - ], **subprocess_args(True)) + ], **subprocess_args(True)) _duration_str = self.handle_ffmpeg_output(ffmpeg_process.stdout) ffmpeg_process.wait() return duration_str_to_float(_duration_str) @@ -309,22 +309,12 @@ class WorkerThread(QThread): os.remove(_f) def encode_video_with_subtitles(self, orig_filename: str, subtitles: list[str], base_ts: float): - create_dt = datetime.fromtimestamp(base_ts) - duration = self.get_video_real_duration(orig_filename) - current_sec = 0 - while current_sec < duration: - if (current_sec + VIDEO_CLIP_OVERFLOW_SEC * 2) > duration: - print("[-]Less than 2 overflow sec, skip") - break - current_dt = (create_dt + timedelta(seconds=current_sec)).strftime("%Y%m%d_%H%M_") - process = get_encode_process_use_handbrake(orig_filename, - subtitles, - os.path.join(VIDEO_OUTPUT_DIR, "{}.mp4".format(current_dt)), - current_sec, - VIDEO_CLIP_EACH_SEC + VIDEO_CLIP_OVERFLOW_SEC) - self.handle_handbrake_output(process.stdout) - process.wait() - current_sec += VIDEO_CLIP_EACH_SEC + current_dt = create_dt = datetime.fromtimestamp(base_ts) + process = get_encode_process_use_handbrake(orig_filename, + subtitles, + os.path.join(VIDEO_OUTPUT_DIR, "{}.mp4".format(current_dt))) + self.handle_handbrake_output(process.stdout) + process.wait() def quick_split_video(self, file): if not os.path.isfile(file): @@ -435,15 +425,13 @@ def danmaku_to_subtitle(file: Union[os.PathLike[str], str], time_shift: float): return new_subtitle_name -def get_encode_process_use_handbrake(orig_filename: str, subtitles: list[str], new_filename: str, start_time: int, stop_time: int): +def get_encode_process_use_handbrake(orig_filename: str, subtitles: list[str], new_filename: str): print("[+]Use HandBrakeCli") encode_process = subprocess.Popen([ HANDBRAKE_EXEC, *_common_handbrake_setting(), "--preset-import-file", HANDBRAKE_PRESET_FILE, "--preset", HANDBRAKE_PRESET, - "--start-at", "seconds:{}".format(start_time), "--stop-at", "seconds:{}".format(stop_time), "-i", orig_filename, "-x", HANDBRAKE_ENCOPT, "--ssa-file", ",".join(i for i in subtitles), - "--ssa-offset", "{}000".format(start_time), "--ssa-burn", ",".join("%d" % (i+1) for i in range(len(subtitles))), "-o", new_filename