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.mkvLook 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-i input.mkv: Specifies the input video file.-map 0:s:0: Selects the first subtitle stream (adjust this index based on your file’s layout).-c:s copy: Copies the subtitle stream without re-encoding it.subtitles.sup: Saves the raw PGS subtitle images to a.supfile.
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.
- Download and install Subtitle Edit (and ensure Tesseract is installed/enabled within it).
- Run the following command in your terminal to convert the extracted
.supfile to.srt:
On Windows:
SubtitleEdit /convert subtitles.sup subripOn Linux/macOS (using Mono):
mono subtitleedit.exe /convert subtitles.sup subripThis 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.
Install Tesseract OCR on your system.
Install the
pgstosrttool via pip:pip install pgstosrtRun 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.