1616 START_BATCH_TO_UPSCALE ,
1717 TMP_VIDEO_PATH ,
1818)
19+ from src .files .batch_utils import (
20+ BatchType ,
21+ delete_default_batches ,
22+ delete_denoise_batches ,
23+ delete_frames ,
24+ )
1925from src .files .file_actions import delete_file
2026from src .frames .frames_helpers import extract_frames_to_batches , get_fps_accurate
21- from src .frames .upscale import delete_frames , upscale_batches
27+ from src .frames .improve import ProcessingType , improve_batches
2228from src .utils .logger import logger
2329from src .video .video_handling import VideoHandler
2430
@@ -39,17 +45,16 @@ async def clean_up(audio: AudioHandler) -> None:
3945 """Удаляет временные файлы."""
4046 logger .debug ("Начало очистки временных файлов" )
4147 delete_tasks = [
42- delete_frames (del_upscaled = False ),
43- delete_frames (del_upscaled = True ),
44- audio .delete_audio_if_exists ()
48+ delete_frames (BatchType .DEFAULT , del_all = True ), # Удаляем все default батчи
49+ delete_frames (BatchType .DENOISE , del_all = True ), # Удаляем все denoise батчи
50+ delete_frames (BatchType .UPSCALE , del_all = True ), # Удаляем все upscale батчи
51+ audio .delete_audio_if_exists (),
4552 ]
4653 delete_tasks .extend (
47- delete_file (f )
48- for f in glob .glob (os .path .join (BATCH_VIDEO_PATH , "*.mp4" ))
54+ delete_file (f ) for f in glob .glob (os .path .join (BATCH_VIDEO_PATH , "*.mp4" ))
4955 )
5056 delete_tasks .extend (
51- delete_file (f )
52- for f in glob .glob (os .path .join (TMP_VIDEO_PATH , "*.mp4" ))
57+ delete_file (f ) for f in glob .glob (os .path .join (TMP_VIDEO_PATH , "*.mp4" ))
5358 )
5459 if delete_tasks :
5560 await asyncio .gather (* delete_tasks )
@@ -80,6 +85,7 @@ async def process_batches(
8085 threads : int ,
8186 ai_threads : str ,
8287 video : VideoHandler ,
88+ ai_waifu2x_path : str ,
8389 ai_realesrgan_path : str ,
8490 start_batch : int ,
8591 end_batch_to_upscale : int ,
@@ -90,9 +96,28 @@ async def process_batches(
9096 end_batch = min (start_batch + threads - 1 , end_batch_to_upscale )
9197 logger .info (f"Обработка батчей с { start_batch } по { end_batch } " )
9298
93- await upscale_batches (
94- threads , ai_threads , ai_realesrgan_path , start_batch , end_batch
99+ # денойз фреймов
100+ await improve_batches (
101+ ProcessingType .DENOISE ,
102+ threads ,
103+ ai_threads ,
104+ ai_waifu2x_path ,
105+ start_batch ,
106+ end_batch ,
107+ )
108+ await delete_default_batches (start_batch , end_batch )
109+ logger .success (f"Батчи { start_batch } -{ end_batch } успешно денойзены" )
110+
111+ # апскейл фреймов
112+ await improve_batches (
113+ ProcessingType .UPSCALE ,
114+ threads ,
115+ ai_threads ,
116+ ai_realesrgan_path ,
117+ start_batch ,
118+ end_batch ,
95119 )
120+ await delete_denoise_batches (start_batch , end_batch )
96121 logger .success (f"Батчи { start_batch } -{ end_batch } успешно апскейлены" )
97122
98123 batches_to_perform = [f"batch_{ i } " for i in range (start_batch , end_batch + 1 )]
@@ -108,6 +133,7 @@ async def main():
108133 try :
109134 my_computer = ComputerParams ()
110135 ai_realesrgan_path = my_computer .ai_realesrgan_path
136+ ai_waifu2x_path = my_computer .ai_waifu2x_path
111137 ai_threads , process_threads = my_computer .get_optimal_threads ()
112138
113139 # логирование параметров системы
@@ -119,6 +145,7 @@ async def main():
119145 f"\n \t Скорость SSD: ~{ my_computer .ssd_speed } MB/s"
120146 f"\n \t RAM: ~{ my_computer .ram_total } GB"
121147 f"\n \t Параметры нейронок: -j { ai_threads } "
148+ f"\n \t Путь к нейронке денойза: { ai_waifu2x_path } "
122149 f"\n \t Путь к нейронке апскейла: { ai_realesrgan_path } "
123150 )
124151
@@ -134,18 +161,19 @@ async def main():
134161 print_bottom ("`сырьё` из видео извлечено" )
135162
136163 # определяем диапазон батчей для обработки
137- print_header ("генерируем апскейленные короткие видео..." )
164+ print_header ("генерируем улучшенные короткие видео..." )
138165 end_batch_to_upscale = calculate_batches ()
139166 logger .info (f"Всего батчей для обработки: { end_batch_to_upscale } " )
140167 await process_batches (
141168 process_threads ,
142169 ai_threads ,
143170 video ,
171+ ai_waifu2x_path ,
144172 ai_realesrgan_path ,
145173 START_BATCH_TO_UPSCALE ,
146174 end_batch_to_upscale ,
147175 )
148- print_bottom ("апскейленные короткие видео сгенерированы" )
176+ print_bottom ("улучшенные короткие видео сгенерированы" )
149177
150178 print_header ("начало финальной сборки видео..." )
151179 total_short_videos = ceil (end_batch_to_upscale / process_threads )
0 commit comments