nrotem commited on
Commit
ad05830
1 Parent(s): ab2f631
Files changed (1) hide show
  1. app.py +37 -25
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
- # Output video file name
7
- output_file = "output_combined.mp4"
8
-
9
- # Run ffmpeg command to combine video and subtitle
10
- cmd = [
11
- "ffmpeg",
12
- "-i", video_file.name,
13
- "-i", subtitle_file.name,
14
- "-c:v", "copy",
15
- "-c:a", "copy",
16
- "-c:s", "mov_text",
17
- "-map", "0:v:0",
18
- "-map", "0:a:0",
19
- "-map", "1",
20
- output_file
21
- ]
22
-
23
- subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
24
- # print("ffmpeg stdout:", subprocess.stdout.decode())
25
- # print("ffmpeg stderr:", subprocess.stderr.decode())
26
-
27
- return output_file
 
 
 
 
 
 
 
 
 
 
 
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."