AndreySokolov01 commited on
Commit
430d36b
1 Parent(s): 8e9d454

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -30
app.py CHANGED
@@ -1,36 +1,30 @@
 
 
1
  import gradio as gr
2
- import ffmpeg
3
- from math import ceil
4
 
5
- def split_video(input_video, duration):
6
- video_info = ffmpeg.probe(input_video)
7
- video_duration = float(video_info['format']['duration'])
8
- num_segments = ceil(video_duration / duration)
9
-
10
- segments = []
11
- for i in range(num_segments):
12
- start_time = i * duration
13
- end_time = min((i + 1) * duration, video_duration)
14
- output_video = f"segment_{i+1}.mp4"
15
-
16
- stream = ffmpeg.input(input_video)
17
- stream = ffmpeg.trim(stream, start=start_time, end=end_time)
18
- stream = ffmpeg.output(stream, output_video)
19
- ffmpeg.run(stream, overwrite_output=True)
20
-
21
- segments.append(output_video)
22
-
23
- return segments
24
 
25
- interface = gr.Interface(
26
- split_video,
27
- inputs=[
28
- gr.File(label="Upload Video"),
29
- gr.Number(label="Segment Duration (seconds)"),
30
- ],
31
- outputs=gr.Files(label="Video Segments"),
 
 
 
 
 
 
 
 
32
  title="Video Splitter",
33
- description="Split a video into equal-duration segments.",
34
  )
35
 
36
- interface.launch()
 
 
1
+ import os
2
+ import moviepy.editor as mp
3
  import gradio as gr
 
 
4
 
5
+ def split_video(video_file, parts):
6
+ video = mp.VideoFileClip(video_file.name)
7
+ duration = video.duration
8
+ part_duration = duration / parts
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ output_files = []
11
+ for part in range(parts):
12
+ start_time = part * part_duration
13
+ end_time = (part + 1) * part_duration
14
+ part_clip = video.subclip(start_time, end_time)
15
+ output_filename = f"part_{part + 1}.mp4"
16
+ part_clip.write_videofile(output_filename, codec="libx264", audio_codec="aac")
17
+ output_files.append(output_filename)
18
+
19
+ return output_files
20
+
21
+ iface = gr.Interface(
22
+ fn=split_video,
23
+ inputs=[gr.inputs.File(type="file", label="Upload Video"), gr.inputs.Slider(minimum=2, maximum=10, default=2, label="Number of Parts")],
24
+ outputs=gr.outputs.Files(label="Download Split Videos"),
25
  title="Video Splitter",
26
+ description="Upload your video and select how many parts you want to split it into."
27
  )
28
 
29
+ if __name__ == "__main__":
30
+ iface.launch()