Spaces:
Runtime error
Runtime error
File size: 1,612 Bytes
cf460e9 ad05830 6f2fdcb d007f3e cf460e9 d007f3e ad05830 cf460e9 ad05830 cf460e9 ad05830 cf460e9 4c38de2 |
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 |
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_{formatted_datetime}.mp4'
cmd1 = [
"ffmpeg",
'-i',
subtitle_file.name,
'subtites.ass','&&' ,"ffmpeg",
"-i",
video_file.name, '-vf' ,'ass=subtitle.ass',
output_file
]
# Run ffmpeg command to combine video and subtitle
cmd2 = [
"ffmpeg", "-i",
video_file.name, '-vf' ,'ass=subtitle.ass',
output_file
]
subprocess.run(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return output_file
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")
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() |