No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-15 06:12:18 -06:00
.forgejo Add skeleton SwiftUI app 2026-11-05 04:20:07 -06:00
.github/workflows define products instead of relying on targets 2026-11-02 03:15:52 -06:00
Sources fix repeated script invocations mixing together & add a printed line for the written file path 2026-11-15 06:12:18 -06:00
Tests macSubtitleOCRError -> SubtitleKitError 2026-11-02 04:11:52 -06:00
.gitignore Many small fixes to improve accuracy (#63) 2026-09-25 17:46:10 -06:00
.swiftformat Update file headers for copyright 2025-01-01 01:01:11 -07:00
Bundler.toml Add skeleton SwiftUI app 2026-11-05 04:20:07 -06:00
CONTRIBUTING.md Refractor and format project (#3) 2024-09-16 23:07:13 -06:00
LICENSE.md Format files 2026-04-12 08:57:46 -06:00
Package.resolved Implement file name passthrough 2026-11-14 23:00:55 -06:00
Package.swift fix FFmpeg variant compilation 2026-11-09 05:07:46 -06:00
README.md Overhaul README 2026-11-02 04:24:54 -06:00

macSubtitleOCR

License

Overview

macSubtitleOCR converts bitmap subtitles into the SubRip subtitle format (SRT) using the macOS Vision framework to perform OCR. Currently PGS and VobSub subtitles are supported.

For more details on OCR accuracy, refer to the Accuracy section below.

Release builds are provided for arm64.

You should be able to compile for x86_64 on you own machine by following the directions in the Building the Project section below.

Features

  • Export raw JSON output from Vision for further analysis
  • Save .png images of subtitles for manual correction of OCR output
  • Optional support for FFmpeg in case of any issues with internal decoder

Supported Formats

  • PGS (.mkv, .sup)
  • VobSub (.mkv, .sub, .idx)

Building the Project

Important

macSubtitleOCR requires Swift 6 support to compile

To make and install the project, follow the directions below:

CLI tool

To build macSubtitleOCR, follow these steps:

git clone https://git.weatherelectric.xyz/greem/macSubtitleOCR
cd macSubtitleOCR
# build with internal decoder only:
swift build --configuration release --product macSubtitleOCR
# OR, build with internal decoder + ffmpeg support:
brew install ffmpeg
USE_FFMPEG=1 swift build --configuration release --product macSubtitleOCR

Running Tests

The testing process compares OCR output against known correct results. Tests aim for at least 95% accuracy, as there are slight differences in Vision results between machines.

swift test

Accuracy

In general, Vision produces a highly accurate output for almost all subtitles. If you find an edge case with degraded performance, open an issue so it can be investigated.

DVD (VobSub) subtitle bitmaps store alternating rows in two separate fields, independently of whether the video is interlaced. The internal decoder reads each field from its recorded offset and interleaves the rows, including the extra first-field row in odd-height bitmaps. This avoids horizontal striping from misaligned fields; no video deinterlacing is needed for subtitle extraction. VobSub packets extracted directly from MKV also include their header bytes in the packet lengths, so short packets retain all their pixel and control data.

In tests comparing Vision's output with Tesseract, Vision consistently gave better results, particularly with tricky cases like properly recognizing I.

While some tools, like SubtitleEdit, may use binary image compare for marginally better accuracy, Vision offers more flexibility with built-in language support.

Note

A --save-images PNG holds the same pixels the run recognized, but it does not always recognize the same. The file records the image as having straight alpha where the run described it as premultiplied, and Vision answers differently for the two even though they resolve to identical pixels. A saved image is therefore reliable for seeing what was extracted, and not for deciding what Vision should have read from it.

Contribution and TODO

For information on how to contribute to the project, please refer to CONTRIBUTING.md.

If you're interested in working on specific features or improvements, check out issues tagged as enhancements.

References