Last active
January 20, 2025 09:03
-
-
Save GiowGiow/9d9d045f0ab1563372c412a906c80891 to your computer and use it in GitHub Desktop.
Sub any video using Open AI Whisper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Install: | |
| # https://github.com/m1guelpf/auto-subtitle | |
| # pip install git+https://github.com/m1guelpf/auto-subtitle.git tqdm | |
| # Move .mkv to the folder where this script is. Then run: | |
| # sub_videos.py | |
| import datetime | |
| from glob import glob | |
| from pathlib import Path | |
| import subprocess | |
| from tqdm import tqdm | |
| if __name__ == "__main__": | |
| video_files = glob("*.mkv") | |
| video_files = sorted(video_files, reverse=True) | |
| for video in tqdm(video_files): | |
| # get name without extension | |
| name = Path(video).stem | |
| # change extension to .srt | |
| new_name = name + ".srt" | |
| # check if file exists | |
| if Path(new_name).exists(): | |
| print(f"Subtitle {new_name} already exists") | |
| else: | |
| print(f"Calling auto-subtitle on video {video}") | |
| full_path_auto_sub = Path.cwd() / "venv/bin/auto_subtitle" | |
| if not Path(full_path_auto_sub).exists(): | |
| print(f"auto-subtitle does not exist") | |
| break | |
| # call autosubtitle using subprocess | |
| process = subprocess.Popen([full_path_auto_sub, video, "--srt_only", "True"]) | |
| # wait for its completion | |
| process.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment