How krmanik/yt-sub-ocr works
1. Repository purpose
- This is a browser userscript for YouTube that extracts hardcoded/burned-in subtitles by running OCR on the video image itself, not on YouTube caption tracks.
- There is no backend service or server-side component; everything runs inside the user’s browser.
2. Top-level architecture
- The repo is very small and effectively split into:
- yt-sub-ocr.user.js: the userscript entrypoint injected into YouTube pages.
- paddleocr.js: the OCR integration/runtime module used by the userscript.
- The README describes the behavior and the external libraries it relies on.
3. Execution boundary
- The script runs in the userscript manager runtime (e.g. Tampermonkey/Greasemonkey) and attaches itself to the YouTube page DOM.
- It operates as an in-page augmentation, meaning it adds UI and behavior without replacing YouTube’s app.
4. UI subsystem
- The userscript adds controls below the video area:
- a Crop action to define the region of interest,
- an OCR action to start recognition.
- It also renders the recognized subtitle text back into the page below the video canvas.
5. Crop/region-selection subsystem
- Cropping is used to limit OCR to the area where subtitles appear.
- The README explicitly states this is powered by cropperjs, so the crop flow is a first-class part of the UI/interaction model rather than a simple fixed screenshot.
6. Video/frame capture and control
- The OCR pipeline works on the current video frame or its rendered canvas representation.
- The script automatically pauses playback during OCR to reduce motion blur and improve recognition accuracy.
- This creates a dependency on YouTube’s player state and DOM structure.
7. OCR subsystem
- OCR is implemented via paddlejs-ocr (mentioned in the README), with paddleocr.js likely acting as the local wrapper or integration layer.
- The OCR engine consumes the selected cropped image region and returns text for display.
8. Data flow
- The flow is:
- YouTube video renders in the browser,
- the user selects a crop region,
- the script pauses playback,
- the selected image region is sent to OCR,
- recognized text is inserted back into the page.
- The main data artifact is thus a cropped video frame image, transformed into subtitle text.
9. External dependencies and their roles
- YouTube: the host application and DOM surface being augmented.
- Userscript manager: the installation/runtime mechanism.
- cropperjs: region selection UI.
- paddlejs-ocr: text recognition engine.
10. Operational characteristics
- The system is interactive and client-side, not batch or headless.
- There is no persistence layer, queue, API, or database.
- The architecture is centered on DOM injection + frame capture + OCR + text display.
11. What an architecture diagram should show
- A single browser client boundary containing:
- the YouTube page/player,
- the injected userscript,
- a crop-selection UI,
- an OCR engine/module,
- and a text output panel.
- The only external dependencies worth showing are the userscript manager and the two libraries above.
Main entry points: yt-sub-ocr.user.js Userscript · paddleocr.js OCR module
Components 10
Browser client
In-page YouTube augmentation running entirely in the browser
- Userscript · Injected script that initializes the OCR workflow on YouTube pages
yt-sub-ocr.user.js - YouTube page · Host page and player surface that the script augments
- Video controls · Crop and OCR actions added below the video area
- Crop selector · Interactive crop flow used to define the subtitle region
- Frame capture · Pauses playback and captures the current video frame or canvas image
- OCR module · Local wrapper around the OCR engine used by the userscript
paddleocr.js - Subtitle text · Recognized text rendered back into the page below the video
External deps
Runtime and library dependencies used by the userscript
- Userscript manager · Tampermonkey/Greasemonkey-style runtime that injects the script
- cropperjs · Library providing the crop region selection interaction
- paddlejs-ocr · OCR engine used to recognize burned-in subtitles from image regions
Connections 12
- Userscript manager → Userscript: injects · Loads the userscript into YouTube pages
- Userscript → YouTube page: attaches to · Binds behavior and UI into the YouTube DOM
- Userscript → Video controls: adds · Creates the Crop and OCR controls below the video
- Video controls → Crop selector: opens · Starts crop-region selection for subtitle extraction
- Crop selector → cropperjs: uses · Region selection is powered by cropperjs
- Video controls → Frame capture: triggers · OCR action causes the current frame to be prepared for recognition
- Frame capture → YouTube page: reads frame · Uses the playing video element or its rendered canvas image
- Frame capture → OCR module: sends image · Passes the cropped frame region into OCR processing
- OCR module → paddlejs-ocr: runs on · Delegates recognition to paddlejs-ocr
- Frame capture → YouTube page: pauses playback · Stops video motion during OCR to improve accuracy
- OCR module → Subtitle text: returns text · Recognized subtitle text is rendered back into the page
- Userscript → OCR module: loads · Imports the OCR integration module