Extract Hardcoded Video Subtitles to SRT Files (No API)

5月7日 Published inVideo Tools

Video-subtitle-extractor (VSE) is a tool designed to identify and extract hardcoded subtitles from video files, converting them into external SRT subtitle files. The entire process runs locally on your machine, requiring no third-party API calls or internet connectivity.

Core Features:

  • Captures keyframes from the video source.
  • Detects the specific positioning of text within each frame.
  • Recognizes text content using OCR.
  • Filters out non-subtitle text elements to ensure accuracy.
  • Removes duplicate lines and generates clean SRT or TXT files.
  • Supports batch processing for multiple videos simultaneously.
  • Compatible with 87 languages, including Simplified Chinese (bilingual Chinese-English), Traditional Chinese, English, Japanese, Korean, and many others.

Extraction Modes:

  • Fast mode: Uses a lightweight model for high-speed processing. While efficient, it may occasionally miss lines or produce minor typos.
  • Auto mode: Automatically selects the model based on your hardware. It utilizes the lightweight model on CPUs and the high-precision model on GPUs, balancing speed and quality.
  • Accurate mode: Employs the high-precision model with frame-by-frame detection on a GPU. This mode ensures no subtitles are missed and minimizes typos, though it is the slowest option.

How to use

  1. Single file: Open your video, adjust the selection box to cover the subtitle area, and click Run.
  2. Batch extract: Select multiple video files. Ensure that all selected videos share the same resolution and subtitle positioning.

Configuration

To generate TXT files instead of SRT, update the configuration by setting GENERATE_TXT=True in backend/config.py.

To automatically remove watermarks or replace specific OCR errors, edit the backend/configs/typoMap.json file. Example configuration:

{
  "l'm": "I'm",
  "l just": "I just",
  "Let'sqo": "Let's go",
  "Iife": "life",
  "威筋": "威胁",
  "性感荷官在线发牌": ""
}

Important: Avoid using Chinese characters or spaces in both the video file paths and the program installation directory. Failure to do so may result in unexpected runtime errors.

Installation

Windows Standalone

Use the Windows single-file version v2.0.0 (CPU version). Simply double-click the executable to run. (Download code: rl02). If your antivirus software flags the file, consider using the portable version instead. Note that the portable version requires an Nvidia GPU.

Install from source

  1. Download and install Miniconda.

  2. Create and activate a new conda environment:

    conda create -n videoEnv python=3.12
    conda activate videoEnv
    
  3. Install the necessary dependencies:

    pip install -r requirements.txt
    
  4. Install CUDA and cuDNN (Nvidia GPU required):

    Windows: Install CUDA 11.7 and the matching cuDNN version. Then run:

    python -m pip install paddlepaddle-gpu==2.6.1.post117 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html
    

    Linux: Install CUDA 11.7 and cuDNN 8.4.1. Then run:

    python -m pip install paddlepaddle-gpu==2.6.1.post117 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html
    

Running the program

  • To launch the graphical interface: python gui.py
  • To run via the command line: python ./backend/main.py

Common issues

  1. Program fails to start / CUDA or cuDNN errors: Verify that you have installed the specific versions of CUDA and cuDNN mentioned in the installation guide.
  2. CondaHTTPError: Ensure your .condarc configuration file is placed correctly in your user home directory.
  3. Windows geos_c.dll error: Uninstall the Shapely library using pip, then reinstall it specifically using the conda install shapely command.
  4. Cannot extract 7z files: Update your 7-Zip software to the latest version to ensure compatibility.