Metadata-Version: 2.4
Name: cshortranslate
Version: 0.2.2
Summary: OCR-based subtitle extraction from video files
Project-URL: Homepage, https://github.com/yourusername/cshortranslate
Project-URL: Issues, https://github.com/yourusername/cshortranslate/issues
Author-email: Your Name <you@example.com>
License-Expression: MIT
License-File: LICENSE
Keywords: chinese,ocr,srt,subtitle,video
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Topic :: Multimedia :: Video
Requires-Python: >=3.9
Requires-Dist: imagehash
Requires-Dist: numpy
Requires-Dist: opencv-python
Requires-Dist: pillow
Requires-Dist: rapidocr
Requires-Dist: tqdm
Provides-Extra: all
Requires-Dist: av; extra == 'all'
Requires-Dist: degirum-video-capture; extra == 'all'
Requires-Dist: ffmpegcv; extra == 'all'
Provides-Extra: degirum
Requires-Dist: degirum-video-capture; extra == 'degirum'
Provides-Extra: ffmpegcv
Requires-Dist: ffmpegcv; extra == 'ffmpegcv'
Provides-Extra: pyav
Requires-Dist: av; extra == 'pyav'
Description-Content-Type: text/markdown

# cshortranslate

OCR-based subtitle extraction from video files. Designed for extracting Chinese subtitles from long drama videos.

## Installation

```bash
pip install cshortranslate
```

For additional video backends:

```bash
pip install cshortranslate[pyav]      # PyAV backend
pip install cshortranslate[ffmpegcv]  # FFmpegCV backend
pip install cshortranslate[degirum]   # Degirum backend
pip install cshortranslate[all]       # All backends
```

## Usage

```bash
cshortranslate video.mp4
cshortranslate video.mp4 -o output.srt
cshortranslate video.mp4 --fps 15 --region "bottom:20"
cshortranslate video.mp4 --preview
```

### Options

| Option | Description |
|---|---|
| `-o, --output` | Output SRT path (default: `<video>.srt`) |
| `--fps` | Frame extraction rate (default: 10) |
| `--region` | Subtitle region: `"bottom:15"` for bottom 15%, or `"x,y,w,h"` in pixels |
| `--preview` | Show first frame with crop overlay for region selection |
| `--lang` | OCR language (default: ch) |
| `--backend` | Video backend: `opencv`, `pyav`, `ffmpegcv`, `degirum` |
| `--batch-size` | Frames to OCR in parallel (default: 1) |
| `--num-workers` | OCR worker threads (default: 1) |
| `--min-chars` | Minimum characters to keep (default: 2) |
| `--min-dur` | Minimum duration in seconds (default: 0.3) |
| `--merge` | Merge N frames vertically before OCR for speed (0=disabled, default: 0) |
| `--no-correct` | Disable OCR confidence-based correction |
| `--dedup-threshold` | Similarity threshold for dedup (default: 0.85) |
| `--max-gap` | Max time gap in seconds between entries to consider merging (default: 2.0) |
| `--dedup-window` | Sliding window size for non-consecutive dedup (0=disabled, default: 5) |
| `--phash-threshold` | Skip OCR if phash delta <= threshold (0=disabled, default: 5) |
| `--phash-mode` | PHash strategy: `pre-ocr`, `ocr-find`, `phash-pair` (default: pre-ocr) |
| `--debug` | Print per-stage timing breakdown after processing |
| `--init` | Generate a default `.cdt` config file |
| `--cdt` | Save current settings to a `.cdt` file |

### Configuration Files

cshortranslate supports `.cdt` configuration files. Place a `.cdt` file with the same name as your video in the same directory:

```bash
# Generate a default config file
cshortranslate --init

# Save current settings to a config file
cshortranslate video.mp4 --region "bottom:15" --fps 15 --cdt
```

Config files are automatically loaded when processing a video.

### PHash Modes

- **pre-ocr**: Skip OCR for frames with similar perceptual hashes (fastest)
- **ocr-find**: OCR first, then use phash on detected text regions
- **phash-pair**: Group-then-verify pipeline for better accuracy

## Requirements

- Python 3.9+
- `rapidocr`
- `opencv-python`
- `tqdm`
- `numpy`
- `imagehash`
- `Pillow`

## License

MIT