Repository navigation
Subtitles OCR
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.
# 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.vttThe input is a bitmap subtitle stream: dvd_subtitle or hdmv_pgs_subtitle.
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_PREFIXenvironment variable. - Pass
-datapath /path/to/tessdata.
Without the file, the encoder stops at start-up and says which file is missing.
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.
- 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.
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.
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.
Users
Filters and components
- Filter-stemsplit
- Filter-lyricsalign
- Whisper-Language-Detection
- Whisper-Word-Timestamps
- Filter-trailingsilence
- Filter-keydetect
- Filter-beatdetect
- Filter-rubberband
- Muxer-Sprite-Sheet
- Muxer-Chapter-VTT
- Muxer-VOBsub
- Protocol-dvdread
- Protocol-OmniDrive
- Auto-Create-Directories
- AACS-and-BDplus
- HLS-Master-Playlist
- Subtitles-OCR
- HEVC-Alpha
Acceleration and codecs
Contributors