From 753cf2160fa9cabab83222e6174ff757ddec7a8c Mon Sep 17 00:00:00 2001 From: Jerry <792602257@qq.com> Date: Tue, 19 Mar 2024 14:01:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E4=B8=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=87=E5=89=B2=E8=A7=86=E9=A2=91=EF=BC=8C?= =?UTF-8?q?=E6=89=80=E4=BB=A5=E5=88=A0=E9=99=A4=E7=9B=B8=E5=85=B3=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=8A=A0=E5=BF=AB=E5=8E=8B=E5=88=B6=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workflow/video.py | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/workflow/video.py b/workflow/video.py index ef549a7..26a63a2 100644 --- a/workflow/video.py +++ b/workflow/video.py @@ -27,39 +27,25 @@ def get_video_real_duration(filename): def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], base_ts: float): create_dt = datetime.fromtimestamp(base_ts) - _duration_str = get_video_real_duration(orig_filename) - duration = duration_str_to_float(_duration_str) - current_sec = 0 - _video_parts = [] - 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, + current_dt = (create_dt).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) - handle_handbrake_output(process.stdout) - process.wait() - _video_parts.append({ + os.path.join(VIDEO_OUTPUT_DIR, "{}.mp4".format(current_dt))) + handle_handbrake_output(process.stdout) + process.wait() + return [{ "base_path": VIDEO_OUTPUT_DIR, "file": "{}.mp4".format(current_dt), - }) - current_sec += VIDEO_CLIP_EACH_SEC - return _video_parts + }] -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