Skip to main content

A tool to detect subtitle languages in media files

Project description

Subtitle Detector

A tool to detect the language of subtitles in media files and standalone subtitle files.

Features

  • Detect languages in embedded subtitles (VOB, ASS, PGS)
  • Analyze standalone subtitle files
  • Support for multiple subtitle tracks
  • Works with text-based and image-based subtitles
  • Uses metadata when available, falls back to content detection

Installation

pip install subdetector

System Requirements

Before using subdetector, install the required system dependencies:

Ubuntu/Debian

sudo apt install ffmpeg tesseract-ocr

macOS

brew install ffmpeg tesseract

Windows

Download and install:

Usage

Basic Commands

# Analyze all subtitle tracks in a media file
subdetector movie.mkv

# Analyze a specific subtitle track (by index)
subdetector movie.mkv -t 2

# Analyze a standalone subtitle file
subdetector subtitle.srt

Command-Line Options

usage: subdetector [-h] [-t TRACK] file

Detect subtitle languages in media files or subtitle files

positional arguments:
  file                  Media file or subtitle file path

optional arguments:
  -h, --help            show this help message and exit
  -t TRACK, --track TRACK
                        Specific subtitle track index to analyze (for media files only)

Examples

Analyzing a Media Container with Multiple Subtitle Tracks

$ subdetector movie.mkv
Detecting subtitle language in: movie.mkv

Results:
Stream #2 (subrip): en [metadata]
Stream #3 (ass): fr [text-detection]
Stream #4 (hdmv_pgs_subtitle): ja [ocr-detection]

Analyzing a Specific Subtitle Track

$ subdetector movie.mkv -t 3
Detecting subtitle language in: movie.mkv

Results:
Stream #3 (ass): fr [text-detection]

Analyzing a Standalone Subtitle File

$ subdetector english_subtitles.srt
Detecting subtitle language in: english_subtitles.srt

Results:
Subtitle file (srt): en [text-detection]

Supported Formats

  • Text-based subtitles:

    • SubRip (.srt)
    • Advanced SubStation Alpha (.ass)
    • SubStation Alpha (.ssa)
    • WebVTT (.vtt)
  • Image-based subtitles:

    • HDMV Presentation Graphic Stream (.sup, .pgs)
    • DVD-Video Object (.sub, .idx)

Detection Method

The tool uses several methods to detect the subtitle language:

  1. Metadata Detection: Checks if the language is specified in the file's metadata.
  2. Text Detection: For text-based subtitles, analyzes the subtitle content.
  3. OCR Detection: For image-based subtitles, performs OCR on extracted frames.

Troubleshooting

No Subtitle Tracks Found

If the tool reports no subtitle tracks found:

  • For MKV files: Ensure subtitles are properly muxed.
  • For standalone files: Check if the file is corrupted.

Unknown Language

If the language is reported as "Unknown":

  • For text subtitles: The subtitle may have too little text or highly specialized terminology.
  • For image subtitles: OCR may have failed due to complex fonts or background.

FFmpeg or Tesseract Errors

Ensure that both FFmpeg and Tesseract OCR are properly installed and in your PATH.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

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

subdetector-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

subdetector-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file subdetector-0.1.0.tar.gz.

File metadata

  • Download URL: subdetector-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for subdetector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e1f919b76ddd2decc0efde6cb1b90033f159993b40f27e8c091a8fc2f15d04b4
MD5 176b1d95d80f2870fcf8575d67d11d9d
BLAKE2b-256 a691acff03cbd14d175186b3f780d84716aaf89693bab09eea41876a3e73a716

See more details on using hashes here.

Provenance

The following attestation bundles were made for subdetector-0.1.0.tar.gz:

Publisher: python-publish.yml on regix1/subdetector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file subdetector-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: subdetector-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for subdetector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45a53f02a21a67dfe547513143bf169ca94a4bea373284cddac35a423cd99fc6
MD5 53facc9cb9ec2ece808566b973fa3456
BLAKE2b-256 b5b24301a66b12c3aa5843caad3f8af39607ab311a96037c480a30f09e5bc9c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for subdetector-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on regix1/subdetector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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