SubtitleEdit/subtitleedit · error · InvalidOperationException

nOCR database is empty: {nOcrDbPath}

Error message

nOCR database is empty: {nOcrDbPath}

What it means

Thrown by NOcrOcrEngine after successfully opening the .nocr file but finding `NOcrDb.TotalCharacterCount == 0`. This means the file exists but contains zero trained character entries, so recognition would return nothing. It guards against a silently broken db being mistaken for an empty subtitle.

Source

Thrown at src/seconv/Core/NOcrOcrEngine.cs:30

{
    public string Name => "nocr";
    private readonly NOcrDb _db;
    private readonly NOcrCaseFixer _caseFixer = new();
    private const int MaxWrongPixels = 25;
    private const int PixelsAreSpaceDefault = 12;

    public NOcrOcrEngine(string nOcrDbPath)
    {
        if (!File.Exists(nOcrDbPath))
        {
            throw new FileNotFoundException(
                $"nOCR database not found: {nOcrDbPath}. Use --ocr-db to point to a .nocr file " +
                "(typically %AppData%\\Subtitle Edit\\OCR\\Latin.nocr or similar).", nOcrDbPath);
        }
        _db = new NOcrDb(nOcrDbPath);
        if (_db.TotalCharacterCount == 0)
        {
            throw new InvalidOperationException($"nOCR database is empty: {nOcrDbPath}");
        }
    }

    public string Recognize(SKBitmap bitmap)
    {
        if (bitmap is null || bitmap.Width == 0 || bitmap.Height == 0)
        {
            return string.Empty;
        }

        var parent = new NikseBitmap2(bitmap);
        parent.MakeTwoColor(200);
        parent.CropTop(0, new SKColor(0, 0, 0, 0));
        var letters = NikseBitmapImageSplitter2.SplitBitmapToLettersNew(
            parent, PixelsAreSpaceDefault, rightToLeft: false, topToBottom: true, minLineHeight: 20, autoHeight: true);

        var matches = new List<NOcrChar>();
        var i = 0;

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Re-download Latin.nocr from the official Subtitle Edit source or copy it from a working SE installation.
  2. Open the .nocr in the Subtitle Edit GUI OCR trainer to confirm it has characters; re-export if empty.
  3. Point --ocr-db at a known-good db file and re-run.
  4. Fall back to tesseract (`--ocr-engine tesseract`) until a valid nOCR db is available.

Example fix

// before
--ocr-db=./Latin.nocr   // 0-byte / corrupt file
// after
--ocr-db=./Latin-good.nocr   // verified non-empty db
Defensive patterns

Strategy: try-catch

Validate before calling

var db = new NOcrDb(path);
if (db.TotalCharacterCount == 0)
    throw new InvalidOperationException("nOCR db has no characters: " + path);

Type guard

static bool IsNocrDbPopulated(string path)
{
    try { return new NOcrDb(path).TotalCharacterCount > 0; }
    catch { return false; }
}

Try / catch

try { var engine = new NOcrOcrEngine(path); }
catch (InvalidOperationException ex) when (ex.Message.Contains("nOCR database is empty"))
{
    // flag corrupt db, skip file, continue batch
}

Prevention

When it happens

Trigger: Constructing `new NOcrOcrEngine(path)` where the file at `path` parses without throwing but yields no character definitions — e.g. an empty placeholder .nocr, a truncated/corrupt download, or a text file mistakenly renamed to .nocr.

Common situations: An interrupted download of Latin.nocr; pointing --ocr-db at a stale or hand-created stub; a .nocr exported from an incompatible SE version whose format changed.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/650d5a6dcfa69bd1. Report an issue: GitHub.