Repository navigation
Conversation
… OCR Filee didn't open .sup files, and picture subtitles can only become text through OCR (KnifeLemon#1872). Filee already has Tesseract (and Apple Vision on macOS). PgsReader reads the PGS segments (compositions, windows, palettes, run-length objects split over several segments, epochs, palette-only updates) and yields each caption with its times as soon as it ends, so a film's worth of bitmaps never sits in memory at once. SubtitleOcr turns each object into dark text on white (padded, doubled when small), reads them in batches through Tesseract's list-file mode (one picture per call if a batch can't be split), cleans the lines (CJK spaces as in KnifeLemon#691) and writes SRT or text with SubtitleWriter; ASS, WebVTT and the rest follow through SRT. Vision gets the same edges. .sup is a read-only Specialist subtitle format in the video-pro field, learned by the subtitles donut in schema 112. Subtitle presets show the OCR language picker (without the OCR switch) in an OCR card of its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The |
KnifeLemon
left a comment
There was a problem hiding this comment.
Thanks for this, @YusufMntm! The PGS reader is careful: segments, RLE, crops and palette indexes are all bounds-checked. The Tesseract list-file batching with the per-picture fallback is a nice touch. A few things before we can merge:
1. Decoded objects can use unbounded memory (blocking)
PgsReader.ParseOds decodes every complete object right away and keeps it in objects[objectId] until an epoch-start PCS.
DecodeRleallocateswidth × heightbytes, up to 16 MiB at the pixel cap, even when the RLE data is empty.- Nothing limits how many object IDs are kept, and ODS segments are parsed even without a PCS.
So a .sup made only of ~24-byte ODS segments with distinct IDs (first+last flags, 4096×4096, no data) holds about 16 GiB after 1,000 segments. That's a 24 KB file. With all 65,536 IDs it's far more. Any of these would fix it:
- cap the objects per epoch (PGS allows 64);
- cap their total decoded bytes;
- keep the RLE and decode an object only when a composition shows it.
2. Per-object size cap
MaxObjectPixels limits the pixel count, so a 65535×256 object passes. With a height under 100, PrepareBitmap then doubles it to about 131k px wide. Could the cap be per side (4096 each, as the description says), or checked against the composition's video size?
3. Palette-only updates
Each palette-only display set re-renders the whole active caption and sums its alpha twice. A small file with many of them makes the conversion crawl. Either of these would avoid it:
- a limit on re-renders per caption;
- comparing the palettes' alpha instead of rendering.
4. OCR language for .sup → TXT
sup → txt uses Pdf.OcrLanguage, but TXT isn't a subtitle target, so the picker only shows when "Recognize text" is on. That switch also changes how PDFs and pictures are handled. Could TXT presets show the picker too, the way subtitle targets do?
5. Schema number
#1994 (.msi) also takes schema 112. Whichever of the two merges second has to move to 113: CurrentSchemaVersion, the from < 113 migration and its test. We'll ping you on the one that needs it.
6. Small wording things
ko.json: the two new strings use 습니다/입니다, and the rest of the file uses 해요체. Suggested: "이 파일에는 Filee가 읽을 수 있는 Blu-ray 자막(.sup)이 없어요" and "그림 자막(.sup)을 읽을 때 쓸 자막 언어예요".en.json: mosterror.*strings have no trailing period, soerror.sup_no_captionscould drop it.
Thanks for the CHANGELOG lines in the comment. We'll add them in the CHANGELOG PR.
Fixes #1872
What and why
.supfiles (Blu-ray PGS picture subtitles) weren't opened at all, and pictures need text recognition before theycan become SRT or ASS. As you suggested, this uses the OCR Filee already has: Tesseract, and Apple Vision on a Mac.
Scope is
.supfiles. VobSub (.idx/.sub) and picture subtitle tracks inside videos are left for follow-ups;MediaEncoding's refusal for those is unchanged.Design
PgsReader(new,Subtitles/): reads the segments, written from the format in Filee's own words.objects split over several data segments, with every run-length code form.
caption. A palette-only update (a fade) stays one caption. A last caption that never ends gets 5 s.
PNG and dropped.
file with nothing readable refuses with the new
error.sup_no_captions.SubtitleOcr(new,Ocr/): objects are read top to bottom, then left to right, and joined by line.255 − luma·alpha/255, so the light fill turns dark and the dark outlinelight), padded 16 px and doubled when under 100 px high, then written with SkiaSharp.
--psm 6, pages split on form feeds), with theexisting parallel runs. If a batch doesn't split into the right number of pages, it falls back to one picture per
call.
(
PdfDocumentReader.IsCjkis nowinternal); Korean keeps its spaces.SubtitleWriter, with temp file + move.TesseractConverterandVisionConvertergetsup → srtandsup → txt(DirectOnly). These are plainedges, not
Ocr: true, since.supalways needs OCR whatever the PDF switch says. ASS, WebVTT, TTML, SAMI, LRC andMicroDVD come through SRT in two steps.
ToPdfAsyncbehaves as before.ITextRecognizerand the same flow, and Vision stays first inEngineRegistry.Pdf.OcrLanguage. To make it choosable, subtitle-target presets show the language pickerwithout the "Recognize text" switch. The OCR rows moved out of the PDF card into an OCR card of their own (shown for
the existing OCR targets as before, plus subtitle targets), with one new caption line,
presets.ocr_language_subtitles. That's the most visible UI change here: if you'd rather keep the rows inside thePDF card, or show the picker only for presets that can take
.sup, I'll change it.supis a read-only subtitle format.FormatFields: Specialist in video-pro, with ASS/TTML/SCC. Schema 112teaches the subtitles donut
.sup(if another PR takes 112 first I'll renumber).SharedPresetVersions: 2.6.0.error.sup_no_captionsandpresets.ocr_language_subtitlesin all 23 files. Docs: README subtitles row anddocs/ENGINES.md(Subtitles, Tesseract, Vision).CHANGELOG.mdis left alone; the lines are in a comment below.Tests
PgsTests(with aPgsBuilderthat draws text, quantizes it and RLE-encodes it into segments):.sup→ SRT, ASS and TXT with both texts and theright times.
OcrRouteTests:sup → srt, the two-step targets, directsup → txt, nosup → docx.SupFormatTests: detection, donut, grade and field, v111 → v112 migration.FormatFieldsTests: Specialist count146 → 147.
RenderTests.Preset_editor_shows_and_saves_text_recognition: SRT and ASS presets show and save the language.Ran locally (Windows, Tesseract 5.4 from
fetch-engines.ps1):Filee.Engines.Tests(Pgs, Subtitle, Ocr: 188 pass,1 unrelated skip),
Filee.Core.Tests(FormatFields, Sup, OcrRoute, SharedPreset, PresetGallery, UserDataStore: 414pass, 1 skip),
Filee.App.Tests(Localization, RenderTests: 737 pass),dotnet format --verify-no-changeson thechanged files.
Not tried: a
.supripped from a real Blu-ray (only files built in the tests), and Apple Vision on a real Mac. Realdiscs have coloured, outlined or italic captions, which may read less cleanly than the test captions.
🤖 Generated with Claude Code