A command-line tool that automatically adds Chinese subtitles to English videos. It uses OpenAI Whisper for speech recognition, Ollama (Qwen2.5) for translation, and ffmpeg to burn subtitles into the video.
Video → ffmpeg (extract audio) → Whisper (transcribe) → Ollama (translate) → ffmpeg (burn subtitles) → Output
- Automatic English speech-to-text via Whisper
- Translation to Simplified or Traditional Chinese via local Ollama LLM
- Three subtitle modes: Chinese-only, English-only, or bilingual (dual)
- Hardcoded subtitles burned directly into video
- Generates intermediate
.srtfiles for manual editing
# Install Ollama model
ollama pull qwen2.5:7bpip install openai-whisper requests# Basic usage (Simplified Chinese subtitles)
python add_chinese_subtitles.py video.mp4
# Traditional Chinese
python add_chinese_subtitles.py video.mp4 --lang traditional
# Bilingual subtitles (English + Chinese)
python add_chinese_subtitles.py video.mp4 --subtitle dual
# English-only subtitles (skip translation)
python add_chinese_subtitles.py video.mp4 --subtitle en
# Use a larger Whisper model for better accuracy
python add_chinese_subtitles.py video.mp4 --whisper-model large| Flag | Choices | Default | Description |
|---|---|---|---|
--lang |
simplified, traditional |
simplified |
Chinese variant |
--subtitle |
zh, en, dual |
zh |
Subtitle mode |
--whisper-model |
tiny, base, small, medium, large |
medium |
Whisper model size |
The output video is saved alongside the input file with a suffix:
video-中文字幕.mp4(Chinese-only)video-英文字幕.mp4(English-only)video-双语字幕.mp4(bilingual)
Intermediate SRT files are saved in a tmp/ directory.
Edit the constants at the top of the script to customize:
BATCH_SIZE = 40 # Subtitle segments per translation call
OLLAMA_URL = "http://localhost:11434/v1/chat/completions"
OLLAMA_MODEL = "qwen2.5:7b"MIT