File size: 1,763 Bytes
430d36b
a52a536
20bee2f
a52a536
709adea
a52a536
 
430d36b
 
709adea
430d36b
a52a536
 
 
 
 
 
 
 
 
 
430d36b
 
 
a52a536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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

# Остальной код остается без изменений