Skip to content

Subtitles OCR

Phillippe Pelzer edited this page Nov 15, 2026 · 2 revisions

ocr_subtitle: OCR subtitle encoder

ocr_subtitle converts bitmap subtitles (DVD and Blu-ray) into WebVTT text. It uses Tesseract. The whole job is one FFmpeg command. No second tool and no separate OCR step are needed.

The encoder is NoMercy-only. It is not in official FFmpeg.

Since: v1.0.31.

Quick example

# First subtitle stream of a DVD rip to WebVTT
ffmpeg -i movie.mkv -map 0:s:0 -c:s ocr_subtitle output.vtt

# French, with the music-note fixups
ffmpeg -i movie.mkv -map 0:s:0 -c:s ocr_subtitle -ocr_language fra -ocr_fixups 1 output.vtt

The input is a bitmap subtitle stream: dvd_subtitle or hdmv_pgs_subtitle.

You need the Tesseract language data

The archives do not contain .traineddata files. Tesseract needs the file for the language you ask for, for example eng.traineddata. Get the files from https://github.com/tesseract-ocr/tessdata. Give it the folder in one of two ways:

  • Set the TESSDATA_PREFIX environment variable.
  • Pass -datapath /path/to/tessdata.

Without the file, the encoder stops at start-up and says which file is missing.

Options

The table is copied from ffmpeg -h encoder=ocr_subtitle of v1.0.47.

Option Type Default Range What it does
ocr_language string eng Tesseract language code, for example fra or deu.
datapath string empty Path to the Tesseract tessdata folder. Empty uses TESSDATA_PREFIX.
ocr_fixups boolean false Fixes common misreads of the music note. Tesseract reads it as J, &, I or ' at the start of a line.
ocr_scale int 3 1 to 8 Upscale factor for the bitmap before OCR. A higher factor helps line detection and costs time.

The help text of ocr_language says the language is "auto-detected from stream, falls back to eng". The encoder source has no such detection. It uses eng unless you set ocr_language. Set it yourself for any language other than English.

How it works

  • Each bitmap is turned into grayscale, weighted by its alpha. Bright text becomes dark, and a dark outline merges with the background. That is what Tesseract reads best.
  • The bitmap is upscaled (nearest neighbour) by ocr_scale.
  • Tesseract reads each subtitle as one block of text.
  • The text goes out as a WebVTT cue with the original timing. Trailing white space is removed.

Where it fits

The usual chain for a DVD: VOBsub keeps the bitmaps as they are. ocr_subtitle makes searchable text of them. Use both if you want both.

Platform notes

The encoder is in every platform archive. Tesseract is linked in on all seven platforms. This page was checked against the source, -h encoder=ocr_subtitle and -encoders of v1.0.47. No OCR run was made in this documentation pass, because no bitmap subtitle sample and no tessdata were at hand.

Clone this wiki locally