import streamlit as st 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 # Streamlit UI st.title("Video Subtitle Combiner") st.write("Combine a video file and a subtitle file using ffmpeg.") video_file = st.file_uploader("Upload Video File", type=["mp4", "avi", "mov"]) subtitle_file = st.file_uploader("Upload Subtitle File", type=["srt"]) if video_file and subtitle_file: st.write("Combining... Please wait.") output_filename = combine_video_subtitle(video_file, subtitle_file) st.success("Video and subtitle combined successfully!") # Display the combined video with open(output_filename, "rb") as f: video_bytes = f.read() st.video(video_bytes) # Provide a link to download the combined video st.download_button("Download Combined Video", video_bytes, file_name=output_filename)