From d69dae0796d49c4fb5beef739b7981ef92055443 Mon Sep 17 00:00:00 2001 From: pat-e Date: Sat, 9 Aug 2025 10:00:03 +0200 Subject: [PATCH] changes the process-call to include the svtav1encapp - stats into the log-file --- anime_audio_helper.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/anime_audio_helper.py b/anime_audio_helper.py index cc74499..c44a4f3 100755 --- a/anime_audio_helper.py +++ b/anime_audio_helper.py @@ -216,11 +216,39 @@ def convert_video(source_file_base, source_file_full, is_vfr, target_cfr_fps_for ) print(f" - Running: {' '.join(ffmpeg_pipe_cmd)} | {' '.join(svtav1_cmd)}") - # Use subprocess.Popen for piping + # Use subprocess.Popen for piping and tee SvtAv1EncApp output + import threading + + # Save the original stdout (console) before redirection + original_console = sys.__stdout__ + with subprocess.Popen(ffmpeg_pipe_cmd, stdout=subprocess.PIPE) as ffmpeg_proc: - with subprocess.Popen(svtav1_cmd, stdin=ffmpeg_proc.stdout) as svt_proc: + with subprocess.Popen( + svtav1_cmd, + stdin=ffmpeg_proc.stdout, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + bufsize=1, + text=True + ) as svt_proc: ffmpeg_proc.stdout.close() # Allow ffmpeg_proc to receive a SIGPIPE if svt_proc exits - svt_proc.communicate() + + def tee_output(proc_stdout, log_file, console): + for line in proc_stdout: + # Write to log file (current sys.stdout) + print(line, end='') # Goes to log file + # Write to console + if console: + try: + console.write(line) + console.flush() + except Exception: + pass + + tee_thread = threading.Thread(target=tee_output, args=(svt_proc.stdout, sys.stdout, original_console)) + tee_thread.start() + svt_proc.wait() + tee_thread.join() if svt_proc.returncode != 0: raise RuntimeError(f"SvtAv1EncApp failed with exit code {svt_proc.returncode}")