Convert PGS to SRT using FFmpeg and OCR

Converting image-based PGS (Presentation Graphic Stream) subtitles from Blu-ray sources into text-based SRT format is essential for media player compatibility and smaller file sizes. Because PGS subtitles are stored as images rather than text, you cannot perform a direct text conversion within FFmpeg alone; instead, you must extract the PGS stream using FFmpeg and then process it through an Optical Character Recognition (OCR) tool. This guide will show you how to extract PGS subtitles using FFmpeg and convert them to SRT using command-line OCR tools.

Step 1: Extract the PGS Subtitle Stream Using FFmpeg

Before you can run OCR, you must extract the PGS subtitle track from your video container (typically an MKV file) into a raw .sup (Subtitle) file.

First, identify the stream index of the subtitle track you want to extract by running:

ffmpeg -i input.mkv

Look for the subtitle stream labeled Subtitle: hdmv_pgs_subtitle. Once you know the stream index (for example, 0:s:0 for the first subtitle track), run the following command to extract it:

ffmpeg -i input.mkv -map 0:s:0 -c:s copy subtitles.sup

Step 2: Convert the SUP File to SRT Using OCR

Since FFmpeg cannot directly translate images to text, you must pass the extracted .sup file through an OCR tool. The most efficient command-line methods are outlined below.

Method A: Using Subtitle Edit (Command Line)

Subtitle Edit is a highly accurate, free tool that uses the Tesseract OCR engine. It features a robust command-line interface perfect for scripting.

  1. Download and install Subtitle Edit (and ensure Tesseract is installed/enabled within it).
  2. Run the following command in your terminal to convert the extracted .sup file to .srt:

On Windows:

SubtitleEdit /convert subtitles.sup subrip

On Linux/macOS (using Mono):

mono subtitleedit.exe /convert subtitles.sup subrip

This command automatically applies OCR to the .sup image database and outputs a clean subtitles.srt file in the same directory.

Method B: Using PGSToSRT (Python & Tesseract)

If you prefer a lightweight, open-source Python tool, you can use pgstosrt, which utilizes tesseract-ocr directly.

  1. Install Tesseract OCR on your system.

  2. Install the pgstosrt tool via pip:

    pip install pgstosrt
  3. Run the conversion command:

    pgstosrt subtitles.sup subtitles.srt

The script will read the PGS images extracted by FFmpeg, pass them to Tesseract, and generate your final SRT text file.