import os import moviepy.editor as mp import gradio as gr from concurrent.futures import ThreadPoolExecutor def split_video(video_file, parts, resolution, quality, audio_enabled, volume): video = mp.VideoFileClip(video_file.name) duration = video.duration part_duration = duration / parts output_files = [] with ThreadPoolExecutor() as executor: futures = [] for part in range(parts): start_time = part * part_duration end_time = (part + 1) * part_duration futures.append(executor.submit(process_part, video, start_time, end_time, resolution, quality, audio_enabled, volume, part)) for future in futures: output_filename = future.result() output_files.append(output_filename) return output_files def process_part(video, start_time, end_time, resolution, quality, audio_enabled, volume, part): part_clip = video.subclip(start_time, end_time) # Настройка параметров кодирования if quality == "Низкое": bitrate = "1M" elif quality == "Среднее": bitrate = "2M" else: bitrate = "4M" # Настройка параметров звука if not audio_enabled: part_clip.audio = None else: part_clip.audio = part_clip.audio.volumex(volume) # Сохранение видео output_filename = f"part_{part + 1}.mp4" part_clip.write_videofile( output_filename, codec="libx264", audio_codec="aac", bitrate=bitrate, preset="medium", ffmpeg_params=["-vf", f"scale={resolution}"], ) return output_filename # Остальной код остается без изменений