app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
+
|
5 |
+
|
6 |
+
def combine_video_subtitle(video_file, subtitle_file):
|
7 |
+
# Output video file name
|
8 |
+
output_file = "output_combined.mp4"
|
9 |
+
|
10 |
+
# Run ffmpeg command to combine video and subtitle
|
11 |
+
cmd = [
|
12 |
+
"ffmpeg",
|
13 |
+
"-i", video_file.name,
|
14 |
+
"-i", subtitle_file.name,
|
15 |
+
"-c:v", "copy",
|
16 |
+
"-c:a", "copy",
|
17 |
+
"-c:s", "mov_text",
|
18 |
+
"-map", "0:v:0",
|
19 |
+
"-map", "0:a:0",
|
20 |
+
"-map", "1",
|
21 |
+
output_file
|
22 |
+
]
|
23 |
+
|
24 |
+
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
25 |
+
|
26 |
+
return output_file
|
27 |
+
|
28 |
+
|
29 |
+
# Create Gradio interface
|
30 |
+
inputs = [
|
31 |
+
gr.inputs.File(label="Video File"),
|
32 |
+
gr.inputs.File(label="Subtitle File")
|
33 |
+
]
|
34 |
+
|
35 |
+
outputs = gr.outputs.File(label="Combined Video with Subtitle")
|
36 |
+
|
37 |
+
title = "Video Subtitle Combiner"
|
38 |
+
description = "Combine a video file and a subtitle file using ffmpeg."
|
39 |
+
|
40 |
+
iface = gr.Interface(fn=combine_video_subtitle, inputs=inputs, outputs=outputs, title=title, description=description)
|
41 |
+
|
42 |
+
# Launch the Gradio interface
|
43 |
+
iface.launch()
|