change of logic for logging
This commit is contained in:
@@ -224,9 +224,11 @@ final_clip.set_output()
|
||||
svtav1_cmd = ["SvtAv1EncApp2"] + svtav1_param_list + ["-i", "-", "-b", str(encoded_video_file)]
|
||||
|
||||
print(f" - Running: {' '.join(vspipe_cmd)} | {' '.join(svtav1_cmd)}")
|
||||
import threading
|
||||
import tempfile
|
||||
|
||||
original_console = sys.__stdout__
|
||||
# Create a temp file to capture SvtAv1EncApp2 output
|
||||
with tempfile.NamedTemporaryFile(mode="w+", encoding="utf-8", delete=False) as svtav1_temp_log:
|
||||
temp_log_path = svtav1_temp_log.name
|
||||
|
||||
with subprocess.Popen(vspipe_cmd, stdout=subprocess.PIPE) as vspipe_proc:
|
||||
with subprocess.Popen(
|
||||
@@ -236,28 +238,18 @@ final_clip.set_output()
|
||||
stderr=subprocess.STDOUT,
|
||||
bufsize=1,
|
||||
text=True
|
||||
) as svt_proc:
|
||||
) as svt_proc, open(temp_log_path, "w", encoding="utf-8") as svt_log:
|
||||
vspipe_proc.stdout.close()
|
||||
|
||||
def tee_output(proc_stdout, console):
|
||||
for line in proc_stdout:
|
||||
if console:
|
||||
try:
|
||||
console.write(line)
|
||||
console.flush()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
tee_thread = threading.Thread(target=tee_output, args=(svt_proc.stdout, original_console))
|
||||
tee_thread.start()
|
||||
# Print to console and write to temp file
|
||||
for line in svt_proc.stdout:
|
||||
print(line, end="")
|
||||
svt_log.write(line)
|
||||
svt_proc.wait()
|
||||
tee_thread.join()
|
||||
|
||||
if svt_proc.returncode != 0:
|
||||
raise RuntimeError(f"SvtAv1EncApp failed with exit code {svt_proc.returncode}")
|
||||
|
||||
print(" --- Finished Video Processing ---")
|
||||
return encoded_video_file, handbrake_cfr_intermediate_file
|
||||
return encoded_video_file, handbrake_cfr_intermediate_file, temp_log_path
|
||||
|
||||
def is_ffmpeg_decodable(file_path):
|
||||
try:
|
||||
@@ -551,6 +543,7 @@ def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None)
|
||||
intermediate_output_file = current_dir / f"output-{file_path.name}"
|
||||
audio_temp_dir = None
|
||||
handbrake_intermediate_for_cleanup = None
|
||||
svtav1_temp_log_path = None
|
||||
try:
|
||||
audio_temp_dir = tempfile.mkdtemp(prefix="anime_audio_")
|
||||
print(f"Audio temporary directory created at: {audio_temp_dir}")
|
||||
@@ -578,7 +571,7 @@ def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None)
|
||||
print(f" - Detected VFR based on MediaInfo FrameRate_Mode: {frame_rate_mode}")
|
||||
original_fps_str = video_track_info.get("FrameRate_Original_String")
|
||||
if original_fps_str:
|
||||
match = re.search(r'\((\d+/\d+)\)', original_fps_str)
|
||||
match = re.search(r'\\((\\d+/\\d+)\\)', original_fps_str)
|
||||
if match:
|
||||
target_cfr_fps_for_handbrake = match.group(1)
|
||||
else:
|
||||
@@ -613,10 +606,35 @@ def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None)
|
||||
else:
|
||||
print(" - No crop needed or detected.")
|
||||
|
||||
encoded_video_file, handbrake_intermediate_for_cleanup = convert_video(
|
||||
# --- Video encoding: get temp log path ---
|
||||
encoded_video_file, handbrake_intermediate_for_cleanup, svtav1_temp_log_path = convert_video(
|
||||
file_path.stem, str(input_file_abs), is_vfr, target_cfr_fps_for_handbrake, autocrop_filter=autocrop_filter
|
||||
)
|
||||
|
||||
# --- After encoding, append summary lines from temp log to main log ---
|
||||
if svtav1_temp_log_path:
|
||||
try:
|
||||
with open(svtav1_temp_log_path, "r", encoding="utf-8") as svt_log:
|
||||
lines = svt_log.readlines()
|
||||
# Find the summary section (look for 'SUMMARY' or last 20 lines)
|
||||
summary_start = None
|
||||
for i, line in enumerate(lines):
|
||||
if 'SUMMARY' in line:
|
||||
summary_start = i
|
||||
break
|
||||
summary_lines = lines[summary_start:] if summary_start is not None else lines[-20:]
|
||||
print("\n--- SvtAv1EncApp2 SUMMARY ---\n")
|
||||
for l in summary_lines:
|
||||
print(l, end="")
|
||||
except Exception as e:
|
||||
print(f"[WARN] Could not append SvtAv1EncApp2 summary to log: {e}")
|
||||
finally:
|
||||
import os
|
||||
try:
|
||||
os.remove(svtav1_temp_log_path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
print("--- Starting Audio Processing ---")
|
||||
processed_audio_files = []
|
||||
audio_tracks_to_remux = []
|
||||
@@ -666,7 +684,7 @@ def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None)
|
||||
mkvmerge_args = ["mkvmerge", "-o", str(intermediate_output_file), str(encoded_video_file)]
|
||||
for file_info in processed_audio_files:
|
||||
sync_switch = ["--sync", f"0:{file_info['Delay']}"] if file_info["Delay"] else []
|
||||
mkvmerge_args += ["--language", f"0:{file_info['Language']}", "--track-name", f"0:{file_info['Title']}"] + sync_switch + [str(file_info["Path"])]
|
||||
mkvmerge_args += ["--language", f"0:{file_info['Language']}", "--track-name", f"0:{file_info['Title']}"] + sync_switch + [str(file_info['Path'])]
|
||||
|
||||
source_copy_args = ["--no-video"]
|
||||
if audio_tracks_to_remux:
|
||||
|
||||
Reference in New Issue
Block a user