doc2video / srt2video.py
zhao1977's picture
Upload 15 files
dd74184 verified
raw
history blame
775 Bytes
import subprocess
import os
def merge_video_and_subtitle(video_and_srt_path, base_name):
video_ext = ".mp4"
srt_ext = ".srt"
video_path = os.path.join(video_and_srt_path, f"{base_name}_with_audio" + video_ext).replace("\\", "/")
srt_path = os.path.join(video_and_srt_path, base_name + srt_ext).replace("\\", "/")
output_path = os.path.join(video_and_srt_path, f"{base_name}_with_audio_with_subs" + video_ext).replace("\\", "/")
command = [
'ffmpeg',
'-i', video_path,
'-vf', f'subtitles={srt_path}',
'-c:a', 'copy',
output_path
]
try:
subprocess.run(command, check=True)
except subprocess.CalledProcessError as e:
print(f"An error occurred while merging video and subtitles: {e}")