From 704d99df4101e19bbc90a2842bb9a9672339dac7 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Thu, 28 Mar 2024 14:11:32 +0100 Subject: [PATCH] Add debug back to ffmpeg --- facefusion/ffmpeg.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/facefusion/ffmpeg.py b/facefusion/ffmpeg.py index 687e4f83..50636bf4 100644 --- a/facefusion/ffmpeg.py +++ b/facefusion/ffmpeg.py @@ -1,21 +1,24 @@ from typing import List, Optional +import os import subprocess import filetype import facefusion.globals -from facefusion import process_manager +from facefusion import logger, process_manager from facefusion.typing import OutputVideoPreset, Fps, AudioBuffer from facefusion.filesystem import get_temp_frames_pattern, get_temp_output_video_path from facefusion.vision import detect_video_fps def run_ffmpeg(args : List[str]) -> bool: - commands = [ 'ffmpeg', '-hide_banner', '-loglevel', 'quiet' ] + commands = [ 'ffmpeg', '-hide_banner', '-loglevel', 'error' ] commands.extend(args) - process = subprocess.Popen(commands, stdout = subprocess.PIPE) + process = subprocess.Popen(commands, stderr = subprocess.PIPE, stdout = subprocess.PIPE) while process_manager.is_processing(): try: + if facefusion.globals.log_level == 'debug': + log_debug(process) return process.wait(timeout = 0.5) == 0 except subprocess.TimeoutExpired: continue @@ -28,6 +31,15 @@ def open_ffmpeg(args : List[str]) -> subprocess.Popen[bytes]: return subprocess.Popen(commands, stdin = subprocess.PIPE, stdout = subprocess.PIPE) +def log_debug(process : subprocess.Popen) -> None: + _, stderr = process.communicate() + errors = stderr.decode().split(os.linesep) + + for error in errors: + if error.strip(): + logger.debug(error.strip(), __name__.upper()) + + def extract_frames(target_path : str, temp_video_resolution : str, temp_video_fps : Fps) -> bool: trim_frame_start = facefusion.globals.trim_frame_start trim_frame_end = facefusion.globals.trim_frame_end @@ -108,7 +120,7 @@ def restore_audio(target_path : str, output_path : str, output_video_fps : Fps) def replace_audio(target_path : str, audio_path : str, output_path : str) -> bool: temp_output_path = get_temp_output_video_path(target_path) - commands = [ '-hwaccel', 'auto', '-i', temp_output_path, '-i', audio_path, '-c:v', 'copy', '-af', 'apad', '-shortest', '-map', '0:v:0', '-map', '1:a:0', '-y', output_path ] + commands = [ '-hwaccel', 'auto', '-i', temp_output_path, '-i', audio_path, '-c:v', 'copy', '-af', 'apad', '-map', '0:v:0', '-map', '1:a:0', '-shortest', '-y', output_path ] return run_ffmpeg(commands)