File size: 2,026 Bytes
430d36b
 
20bee2f
709adea
e4082bc
430d36b
 
 
709adea
430d36b
 
 
 
 
e4082bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430d36b
e4082bc
 
 
 
 
 
 
 
430d36b
 
 
 
 
 
425280d
e4082bc
 
 
 
 
 
425280d
f0ab618
1107c78
430d36b
abdd75f
e4082bc
430d36b
 
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
56
57
58
59
60
import os
import moviepy.editor as mp
import gradio as gr

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 = []
    for part in range(parts):
        start_time = part * part_duration
        end_time = (part + 1) * part_duration
        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}"],
        )
        output_files.append(output_filename)

    return output_files

iface = gr.Interface(
    fn=split_video,
    inputs=[
        gr.File(label="Upload Video"),
        gr.Slider(minimum=2, maximum=10, value=2, label="Number of Parts"),
        gr.Dropdown(choices=["720p", "1080p", "4K"], label="Resolution"),
        gr.Dropdown(choices=["Низкое", "Среднее", "Высокое"], label="Качество"),
        gr.Checkbox(label="Включить звук"),
        gr.Slider(minimum=0, maximum=2, value=1, label="Громкость"),
    ],
    outputs=gr.Files(label="Download Split Videos"),
    title="Video Splitter",
    description="Upload your video and select how many parts you want to split it into."
)

if __name__ == "__main__":
    iface.launch()