Spaces:
Runtime error
Runtime error
| 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 | |
| ] | |
| print(os.getcwd()) | |
| file_path = os.path.join(os.getcwd() , "subtitle.ass" ) | |
| res = subprocess.run(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| print(res) | |
| return [file_path ,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) |