app.py
CHANGED
@@ -1,38 +1,50 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import os
|
|
|
4 |
|
5 |
def combine_video_subtitle(video_file, subtitle_file):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# Create Gradio interface
|
30 |
inputs = [
|
31 |
-
gr.File(label="Video File"),
|
32 |
-
gr.File(label="Subtitle File")
|
33 |
]
|
34 |
|
35 |
-
outputs = gr.File(label="Combined Video with Subtitle")
|
36 |
|
37 |
title = "Video Subtitle Combiner"
|
38 |
description = "Combine a video file and a subtitle file using ffmpeg."
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import os
|
4 |
+
import datetime
|
5 |
|
6 |
def combine_video_subtitle(video_file, subtitle_file):
|
7 |
+
# Output video file name
|
8 |
+
try:
|
9 |
+
current_datetime = datetime.datetime.now()
|
10 |
+
formatted_datetime = current_datetime.strftime("%Y%m%d_%H%M%S")
|
11 |
+
|
12 |
+
output_file = f'output_combined_{formatted_datetime}.mp4'
|
13 |
+
|
14 |
+
cmd1 = [
|
15 |
+
"ffmpeg",
|
16 |
+
'-i',
|
17 |
+
subtitle_file.name,
|
18 |
+
'subtites.ass','&&' ,"ffmpeg",
|
19 |
+
"-i",
|
20 |
+
video_file.name, '-vf' ,'ass=subtitle.ass',
|
21 |
+
|
22 |
+
output_file
|
23 |
+
]
|
24 |
+
# Run ffmpeg command to combine video and subtitle
|
25 |
+
cmd2 = [
|
26 |
+
"ffmpeg", "-i",
|
27 |
+
video_file.name, '-vf' ,'ass=subtitle.ass',
|
28 |
+
|
29 |
+
output_file
|
30 |
+
]
|
31 |
+
|
32 |
+
subprocess.run(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
33 |
+
|
34 |
+
|
35 |
+
return output_file
|
36 |
+
except subprocess.CalledProcessError as e:
|
37 |
+
error_message = f"An error occurred: {e.returncode}\n{e.stderr.decode()}"
|
38 |
+
print(error_message)
|
39 |
+
return None, error_message
|
40 |
|
41 |
# Create Gradio interface
|
42 |
inputs = [
|
43 |
+
gr.inputs.File(label="Video File"),
|
44 |
+
gr.inputs.File(label="Subtitle File")
|
45 |
]
|
46 |
|
47 |
+
outputs = gr.outputs.File(label="Combined Video with Subtitle")
|
48 |
|
49 |
title = "Video Subtitle Combiner"
|
50 |
description = "Combine a video file and a subtitle file using ffmpeg."
|