Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

video-chinese-subtitle

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.

Pipeline

Video → ffmpeg (extract audio) → Whisper (transcribe) → Ollama (translate) → ffmpeg (burn subtitles) → Output

Features

  • 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 .srt files for manual editing

Prerequisites

  • Python 3.10+
  • ffmpeg (must be in PATH)
  • Ollama running locally with qwen2.5:7b model
# Install Ollama model
ollama pull qwen2.5:7b

Installation

pip install openai-whisper requests

Usage

# 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

Options

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

Output

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.

Configuration

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"

License

MIT

About

A command-line tool that automatically adds Chinese subtitles to English videos

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages