File size: 1,054 Bytes
9ad39f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import subprocess
import os


def combine_video_subtitle(video_file, subtitle_file):
    # Output video file name
    output_file = "output_combined.mp4"

    # Run ffmpeg command to combine video and subtitle
    cmd = [
        "ffmpeg",
        "-i", video_file.name,
        "-i", subtitle_file.name,
        "-c:v", "copy",
        "-c:a", "copy",
        "-c:s", "mov_text",
        "-map", "0:v:0",
        "-map", "0:a:0",
        "-map", "1",
        output_file
    ]

    subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    return output_file


# 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")

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()