PySub is a command-line utility that transcribes audio from video files and optionally translates the text into another language using either OpenAI or Ollama as the language model provider. Subtitles are exported in .srt format and are fully timestamped.
- 🎧 Audio extraction from
.mp4videos - 📝 Automatic English transcription using OpenAI Whisper
- 🌐 Optional translation into other languages (e.g. Thai, Isan, etc.)
- 🔄 Switch between OpenAI or Ollama (local LLM) via config file
- 📄 Outputs clean
.srtsubtitle files - 📦 JSON-based configuration with schema validation
- 📋 Logging with translation line tracking and error handling
python main.py input_video.mp4 output_subtitles.srt --config config.jsonAll settings are provided via a JSON config file. Here's an example config.json:
{
"translate": true,
"target_language": "thai",
"api_key": "sk-...", // Only needed for OpenAI
"provider": "ollama", // "openai" or "ollama"
"ollama_model": "gemma:7b" // Optional, defaults to "llama3"
}1
00:00:00,000 --> 00:00:03,000
ขอบคุณที่อยู่กับฉัน
2
00:00:03,001 --> 00:00:06,000
ฉันรักคุณมากInstall dependencies with:
pip install -r requirements.txtjsonschema==4.24.0
moviepy==2.2.1
openai==1.86.0
openai_whisper==20240930
Requests==2.32.4
srt==3.5.3
If using provider: "ollama" in your config:
- Install Ollama
- Pull a supported model (e.g.
gemma:7borllama3):ollama pull gemma:7b ollama run gemma:7b
- Ensure it's running at
http://localhost:11434
Never commit API keys to your repo. Use .gitignore, environment variables, or secured config files.
If a key has leaked in Git history, refer to Removing sensitive data from Git.
├── main.py
├── config.json
├── requirements.txt
├── schemas/
│ └── pysub.schema.json
├── output.srt
├── pysub.log
- Batch processing of multiple video files
- GUI wrapper
- Translation memory / caching
-
.vttsubtitle support
MIT License © 2025 Christopher M. Horlick
This project is not affiliated with OpenAI or Ollama.