changes the process-call to include the svtav1encapp - stats into the log-file

This commit is contained in:
2025-08-09 10:00:03 +02:00
parent 0edbd7c0c7
commit d69dae0796

View File

@@ -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)}") 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(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 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: if svt_proc.returncode != 0:
raise RuntimeError(f"SvtAv1EncApp failed with exit code {svt_proc.returncode}") raise RuntimeError(f"SvtAv1EncApp failed with exit code {svt_proc.returncode}")