Skip to main content

视频英文字幕翻译为中文字幕工具

Project description

🎬 Video Subtitle Translation Tool

Automatically transcribe video audio, translate to target language, and generate subtitle files or embed them into videos. Supports translation between 18 languages.

中文文档 | 日本語ドキュメント | 한국어 문서

✨ Features

  • 🎤 Speech Recognition: High-precision speech recognition using OpenAI Whisper
  • 🌐 Multi-language Translation: Supports translation between 18 languages (Chinese, English, Japanese, Korean, French, German, Spanish, etc.)
  • 🤖 Multiple Engine Support: Supports DeepSeek, OpenAI, and other translation engines
  • 📄 Subtitle Generation: Supports multiple subtitle formats including SRT, VTT, ASS
  • 🎥 Subtitle Embedding: Supports both soft and hard subtitle methods
  • 🌍 Bilingual Subtitles: Optional bilingual subtitle generation
  • 💰 Cost-Effective: DeepSeek API offers affordable pricing with excellent translation quality
  • 🏗️ Modular Design: Easy to extend and maintain

🌍 Supported Languages

Code Language Code Language
zh Chinese (中文) en English
ja Japanese (日本語) ko Korean (한국어)
fr French (Français) de German (Deutsch)
es Spanish (Español) ru Russian (Русский)
pt Portuguese (Português) it Italian (Italiano)
nl Dutch (Nederlands) pl Polish (Polski)
tr Turkish (Türkçe) ar Arabic (العربية)
hi Hindi (हिन्दी) th Thai (ไทย)
vi Vietnamese (Tiếng Việt) id Indonesian (Bahasa Indonesia)

Use video-translate --list-languages to view the complete list.

📁 Project Structure

video-translate/
├── src/
│   └── video_translate/
│       ├── __init__.py      # Package initialization
│       ├── __main__.py      # Entry point
│       ├── cli.py           # Command-line interface
│       ├── config.py        # Configuration management
│       ├── models.py        # Data models
│       ├── transcriber.py   # Speech recognition module
│       ├── translator.py    # Translation module
│       ├── subtitle.py      # Subtitle processing module
│       ├── video.py         # Video processing module
│       ├── pipeline.py      # Processing pipeline
│       └── utils.py         # Utility functions
├── pyproject.toml           # Project configuration
├── requirements.txt         # Dependencies
├── LICENSE                  # MIT License
├── .gitignore               # Git ignore file
└── README.md

📦 Installation

Prerequisites

FFmpeg is required for video processing. Please install it first:

macOS:

# Basic installation (sufficient for soft subtitles)
brew install ffmpeg

# For hard subtitles (--hard-sub), you need FFmpeg with libass support:
brew install ffmpeg-full
echo 'export PATH="/opt/homebrew/opt/ffmpeg-full/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Note: The standard brew install ffmpeg does not include libass support, which is required for the --hard-sub feature. If you encounter errors like "No option name near force_style", please install ffmpeg-full instead.

Ubuntu/Debian:

sudo apt update && sudo apt install ffmpeg

The apt package typically includes libass support. If you encounter "No option name near force_style" errors with --hard-sub, install libass: sudo apt install libass-dev and reinstall ffmpeg.

Windows: Download and install FFmpeg (recommended: gyan.dev full build or BtbN builds, which include libass support)

Quick Installation (Recommended)

pip install video-translate

Or use uv (faster):

uv pip install video-translate

Development Installation

If you want to contribute to development or modify the code:

# 1. Clone the project
git clone https://github.com/yourusername/video-translate.git
cd video-translate

# 2. Install uv (if not already installed)
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# 3. Install dependencies (including dev tools)
uv sync --dev

# Or install with pip in editable mode
pip install -e ".[dev]"

Set up API Key

Register and get an API Key from DeepSeek Open Platform:

export DEEPSEEK_API_KEY='your-api-key-here'

Or use OpenAI:

export OPENAI_API_KEY='your-api-key-here'

🚀 Usage

Command Line Usage

# Basic usage (English → Chinese)
video-translate video.mp4

# Or use python -m
python -m video_translate video.mp4

Multi-language Translation Examples

# English → Chinese (default)
video-translate video.mp4

# Japanese → Chinese
video-translate video.mp4 --source ja --target zh

# English → Japanese
video-translate video.mp4 --source en --target ja

# Chinese → English
video-translate video.mp4 --source zh --target en

# Korean → Japanese
video-translate video.mp4 --source ko --target ja

# French → German
video-translate video.mp4 --source fr --target de

Command Line Options

Option Description
-s, --source Source language code (default: en)
-t, --target Target language code (default: zh)
--list-languages List all supported languages
-o, --output Specify output directory
-m, --model Whisper model size (tiny/base/small/medium/large)
--translator Translation engine (deepseek/openai)
--api-key Translation API Key
--target-only Output only target language subtitles, without source text
--source-first Source language on top, target language below
--no-embed Don't embed subtitles into video, only generate subtitle files
--hard-sub Use hard subtitles (burned into video)
--font-size Hard subtitle font size (default: 24)

More Examples

# Use a larger model for better accuracy
video-translate video.mp4 --model large

# Only generate subtitle files, don't embed into video
video-translate video.mp4 --no-embed

# Generate hard subtitles (burned into video)
video-translate video.mp4 --hard-sub

# Output only target language subtitles
video-translate video.mp4 --target-only

# Use OpenAI translation
video-translate video.mp4 --translator openai

# Specify output directory
video-translate video.mp4 -o ./output

Use as a Library

from video_translate import (
    Config,
    TranscriberConfig,
    TranslatorConfig,
    TranslationPipeline,
    WhisperModel,
    TranslatorType,
    Language,
)

# Create configuration - Japanese to Chinese translation
config = Config(
    transcriber=TranscriberConfig(
        model=WhisperModel.BASE,
        language="ja"  # Source language
    ),
    translator=TranslatorConfig(
        type=TranslatorType.DEEPSEEK,
        api_key="your-api-key",
        source_language=Language.JAPANESE,
        target_language=Language.CHINESE,
    ),
)

# Create processing pipeline
pipeline = TranslationPipeline(config)

# Process video
result = pipeline.process("video.mp4")

print(f"Subtitle file: {result['subtitle_file']}")
print(f"Output video: {result['output_video']}")

🤖 Whisper Model Selection

Model Size Memory Speed Accuracy
tiny 39M ~1GB Fastest Lower
base 74M ~1GB Fast Medium
small 244M ~2GB Medium Good
medium 769M ~5GB Slow High
large 1550M ~10GB Slowest Highest

Recommendations:

  • Quick preview: Use tiny or base
  • Production use: Use small or medium
  • Highest quality: Use large

🔌 Extending Translation Engines

The project uses a modular design, making it easy to add new translation engines:

from video_translate.translator import BaseTranslator

class MyTranslator(BaseTranslator):
    @property
    def name(self) -> str:
        return "MyTranslator"

    def translate_text(self, text: str, context: str = "") -> str:
        # Implement translation logic
        pass

    def translate_batch(self, texts: list[str]) -> list[str]:
        # Implement batch translation logic
        pass

📁 Output Files

  • videoname_{language_code}.srt - Subtitle file (e.g., video_zh.srt, video_ja.srt)
  • videoname_{language_code}.mp4 - Video with embedded subtitles (if embedding is selected)

⚠️ Notes

  1. First run will automatically download the Whisper model, please ensure a stable internet connection
  2. Hard subtitles will re-encode the video, which takes longer
  3. Soft subtitles only copy streams, faster but may not be supported by some players
  4. Ensure FFmpeg is installed on your system
  5. Apple Silicon Macs will automatically use MPS acceleration

🛠️ Development

# Install development dependencies
uv sync --dev

# Run tests
uv run pytest

# Code formatting
uv run black src/

# Code linting
uv run ruff check src/

# Type checking
uv run mypy src/

📄 License

This project is open-sourced under the MIT License.

Copyright (c) 2026 innovationmech

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

video_translate-1.1.0.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

video_translate-1.1.0-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file video_translate-1.1.0.tar.gz.

File metadata

  • Download URL: video_translate-1.1.0.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for video_translate-1.1.0.tar.gz
Algorithm Hash digest
SHA256 428c4528793200d0045183125294192e498f681ed5e1456cb9f4220af5c27875
MD5 295474687d3bac5948e2125a6d1b92d2
BLAKE2b-256 559b44471e35b9f7f364906810f71e5c63c811f1dbb7d81beffdbd422208b943

See more details on using hashes here.

File details

Details for the file video_translate-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: video_translate-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for video_translate-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 750c8a0f32af0ca6bb7b095be020047181d1269d90b3c1b6cf9a6a8b87411e31
MD5 fd1b59032ab9e2508ff9bcb8e1d5c7a6
BLAKE2b-256 bef710ac94b83241ec6efd23478a18517842d272422a07db9105de2a5e97f4bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page