A Python script that automates video subtitle creation & translation, supporting both local files and online video URLs.
Here are some examples of the script in action:
Run the script using the following command:
python translate.py video_input target_language [options]
video_input
: URL or path to the input video filetarget_language
: Target language for translation (e.g., Spanish, English, French)--output_dir
: Directory to save output files (default: "output")--models_path
: Path to store Whisper models (default: "Models")--openai_api_key
: OpenAI API key (if not set as an environment variable)--font
: Font to use for subtitles (default: "NanumGothic")--use_local_whisper
: Use local Whisper model for transcription instead of ChatGPT's WhisperTranslate YouTube video subtitles to Spanish (using default ChatGPT Whisper):
python translate.py https://www.youtube.com/watch?v=VIDEO_ID Spanish
Translate local video file subtitles to French (using default ChatGPT Whisper):
python translate.py /path/to/your/video.mp4 French
Use a specific output directory and font:
python translate.py input_video.mp4 German --output_dir my_output --font Arial
Use a local model for transcription:
python translate.py input_video.mp4 Korean --use_local_whisper
bin
folder path to system PATHffmpeg -version
brew install ffmpeg
sudo apt update
sudo apt install ffmpeg
Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
Install required packages:
pip install openai==1.12.0
pip install faster-whisper==0.10.0
pip install yt-dlp==2024.3.10
pip install ffmpeg-python==0.2.0
pip install pydub==0.25.1
# Linux/macOS
export OPENAI_API_KEY='your-key-here'
# Windows (PowerShell)
$env:OPENAI_API_KEY='your-key-here'
git clone https://github.com/tikene/video-caption-and-translate.git
cd video-caption-and-translate
python translate.py --help
ffmpeg -version
The script generates the following files in the output directory:
This project is licensed under the MIT License - see the LICENSE file for details.