11import asyncio
2+ import glob
23import os
34import re
45from datetime import datetime
6+ from math import ceil
57
68from src .audio .audio_handling import AudioHandler
79from src .config .comp_params import ComputerParams
810from src .config .settings import (
11+ BATCH_VIDEO_PATH ,
912 END_BATCH_TO_UPSCALE ,
1013 FINAL_VIDEO ,
1114 INPUT_BATCHES_DIR ,
1215 ORIGINAL_VIDEO ,
1316 START_BATCH_TO_UPSCALE ,
17+ TMP_VIDEO_PATH ,
1418)
19+ from src .files .file_actions import delete_file
1520from src .frames .frames_helpers import extract_frames_to_batches , get_fps_accurate
1621from src .frames .upscale import delete_frames , upscale_batches
1722from src .utils .logger import logger
@@ -26,7 +31,7 @@ def print_header(title: str) -> None:
2631
2732def print_bottom (title : str ) -> None :
2833 logger .info (f"✅ { title .upper ()} " .center (50 ))
29- logger .info (f"{ '=' * 50 } " )
34+ logger .info (f"{ '=' * 50 } \n " )
3035
3136
3237async def clean_up (audio : AudioHandler ) -> None :
@@ -36,6 +41,12 @@ async def clean_up(audio: AudioHandler) -> None:
3641 asyncio .to_thread (audio .delete_audio_if_exists ),
3742 asyncio .to_thread (delete_frames , del_upscaled = False ),
3843 asyncio .to_thread (delete_frames , del_upscaled = True ),
44+ asyncio .to_thread (
45+ map , delete_file , glob .glob (os .path .join (BATCH_VIDEO_PATH , "*.mp4" ))
46+ ),
47+ asyncio .to_thread (
48+ map , delete_file , glob .glob (os .path .join (TMP_VIDEO_PATH , "*.mp4" ))
49+ ),
3950 )
4051 logger .debug ("Временные файлы успешно удалены" )
4152
@@ -80,13 +91,7 @@ async def process_batches(
8091 logger .success (f"Батчи { start_batch } -{ end_batch } успешно апскейлены" )
8192
8293 batches_to_perform = [f"batch_{ i } " for i in range (start_batch , end_batch + 1 )]
83- short_video = await video .build_short_video (batches_to_perform )
84- if short_video :
85- logger .info (f"Видео собрано: { short_video } " )
86- await asyncio .to_thread (delete_frames , del_upscaled = True )
87- logger .debug (
88- f"Обработанные кадры удалены из батчей { start_batch } -{ end_batch } "
89- )
94+ video .build_short_video (batches_to_perform )
9095 start_batch += threads
9196
9297
@@ -104,21 +109,21 @@ async def main():
104109 logger .info (
105110 "Параметры системы:"
106111 f"\n \t ОС: { my_computer .cpu_name } "
107- f"\n \t Ядра : { my_computer .cpu_threads } "
112+ f"\n \t CPU потоки : { my_computer .cpu_threads } "
108113 f"\n \t Безопасные потоки: { my_computer .safe_cpu_threads } "
109- f"\n \t Скорость SSD: { my_computer .ssd_speed } MB/s"
110- f"\n \t RAM: { my_computer .ram_total } GB"
114+ f"\n \t Скорость SSD: ~ { my_computer .ssd_speed } MB/s"
115+ f"\n \t RAM: ~ { my_computer .ram_total } GB"
111116 f"\n \t Параметры нейронок: -j { ai_threads } "
112117 f"\n \t Путь к нейронке апскейла: { ai_realesrgan_path } "
113118 )
114119
115120 print_header ("извлекаем 'сырьё' из видео..." )
116- audio = AudioHandler (threads = process_threads )
121+ audio = AudioHandler (threads = my_computer . safe_cpu_threads // 2 )
117122 await clean_up (audio )
118123
119124 # запускаем извлечение аудио из видео в фоне
120125 asyncio .create_task (audio .extract_audio ())
121- extract_frames_to_batches (process_threads )
126+ extract_frames_to_batches (my_computer . safe_cpu_threads // 2 )
122127 fps = await asyncio .to_thread (get_fps_accurate , ORIGINAL_VIDEO )
123128 video = VideoHandler (fps = fps )
124129 print_bottom ("`сырьё` из видео извлечено" )
@@ -135,11 +140,11 @@ async def main():
135140 START_BATCH_TO_UPSCALE ,
136141 end_batch_to_upscale ,
137142 )
138- await asyncio .to_thread (delete_frames , del_upscaled = False )
139143 print_bottom ("апскейленные короткие видео сгенерированы" )
140144
141145 print_header ("начало финальной сборки видео..." )
142- final_merge = video .build_final_video ()
146+ total_short_videos = ceil (end_batch_to_upscale / process_threads )
147+ final_merge = await video .build_final_video (total_short_videos )
143148 logger .success (f"Общее видео собрано: { final_merge } " )
144149
145150 logger .info ("Добавление аудиодорожки к финальному видео" )
0 commit comments