File size: 1,730 Bytes
cf460e9
 
 
ad05830
6f2fdcb
d007f3e
cf460e9
d007f3e
ad05830
 
 
 
 
dff9e3f
ad05830
 
 
 
 
baa9087
 
 
 
 
ad05830
8fd5eb0
ad05830
 
 
 
 
 
 
 
89b7071
baa9087
ad05830
f452cdb
ad05830
 
 
 
cf460e9
 
 
ad05830
 
cf460e9
 
89b7071
cf460e9
 
 
 
 
 
 
baa9087
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
import gradio as gr
import subprocess
import os
import datetime
from ffmpy import FFmpeg
from tempfile import _TemporaryFileWrapper

def combine_video_subtitle(video_file :_TemporaryFileWrapper , subtitle_file):
      # Output video file name
    try:
      current_datetime = datetime.datetime.now()
      formatted_datetime = current_datetime.strftime("%Y%m%d_%H%M%S")

      output_file = f'output_combined_.mp4' #{formatted_datetime}.mp4'

      cmd1 = [
          "ffmpeg",
          '-i',
          subtitle_file.name,
          'subtites.ass',
          # '&&' ,"ffmpeg",
          # "-i",
          #  video_file.name, '-vf' ,'ass=subtitle.ass',
          # output_file
      ]
      print(video_file.name ) 
      # Run ffmpeg command to combine video and subtitle
      cmd2 = [
          "ffmpeg", "-i",
            video_file.name, '-vf' ,'ass=subtitle.ass',

          output_file
      ]

      res = subprocess.run(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      print(res)    
      
      return ["subtitle.ass" ,res]
    except subprocess.CalledProcessError as e:
          error_message = f"An error occurred: {e.returncode}\n{e.stderr.decode()}"
          print(error_message)
          return None, error_message

# Create Gradio interface
inputs = [
    gr.inputs.File(label="Video File"),
    gr.inputs.File(label="Subtitle File")
]

outputs = [gr.outputs.File(label="Combined Video with Subtitle") ,gr.Textbox()]

title = "Video Subtitle Combiner"
description = "Combine a video file and a subtitle file using ffmpeg."

iface = gr.Interface(fn=combine_video_subtitle, inputs=inputs, outputs=outputs, title=title, description=description)

# Launch the Gradio interface
iface.launch(debug =True)