Fix audio range in restore audio

This commit is contained in:
henryruhs
2025-01-31 22:26:17 +01:00
parent ddd83d0606
commit 51a809310e
2 changed files with 5 additions and 4 deletions

View File

@@ -476,7 +476,7 @@ def process_video(start_time : float) -> ErrorCode:
logger.warn(wording.get('replacing_audio_skipped'), __name__)
move_temp_file(state_manager.get_item('target_path'), state_manager.get_item('output_path'))
else:
if restore_audio(state_manager.get_item('target_path'), state_manager.get_item('output_path'), temp_video_fps, trim_frame_start, trim_frame_end):
if restore_audio(state_manager.get_item('target_path'), state_manager.get_item('output_path'), trim_frame_start, trim_frame_end):
logger.debug(wording.get('restoring_audio_succeed'), __name__)
else:
if is_process_stopping():

View File

@@ -10,7 +10,7 @@ from facefusion import ffmpeg_builder, logger, process_manager, state_manager, w
from facefusion.filesystem import get_file_format, remove_file
from facefusion.temp_helper import get_temp_file_path, get_temp_frames_pattern, resolve_temp_frame_paths
from facefusion.typing import AudioBuffer, Commands, EncoderSet, Fps, UpdateProgress
from facefusion.vision import count_trim_frame_total, detect_video_duration, restrict_video_fps
from facefusion.vision import count_trim_frame_total, detect_video_duration, detect_video_fps, restrict_video_fps
def run_ffmpeg_with_progress(commands : Commands, update_progress : UpdateProgress) -> subprocess.Popen[bytes]:
@@ -156,16 +156,17 @@ def read_audio_buffer(target_path : str, audio_sample_rate : int, audio_sample_s
return None
def restore_audio(target_path : str, output_path : str, temp_video_fps : Fps, trim_frame_start : int, trim_frame_end : int) -> bool:
def restore_audio(target_path : str, output_path : str, trim_frame_start : int, trim_frame_end : int) -> bool:
output_audio_encoder = state_manager.get_item('output_audio_encoder')
output_audio_quality = state_manager.get_item('output_audio_quality')
output_audio_volume = state_manager.get_item('output_audio_volume')
target_video_fps = detect_video_fps(state_manager.get_item('target_path'))
temp_file_path = get_temp_file_path(target_path)
temp_video_duration = detect_video_duration(temp_file_path)
commands = ffmpeg_builder.chain(
ffmpeg_builder.set_input(temp_file_path),
ffmpeg_builder.select_media_range(trim_frame_start, trim_frame_end, temp_video_fps),
ffmpeg_builder.select_media_range(trim_frame_start, trim_frame_end, target_video_fps),
ffmpeg_builder.set_input(target_path),
ffmpeg_builder.copy_video_encoder(),
ffmpeg_builder.set_audio_encoder(output_audio_encoder),