CommunityImagegithub.com

screen-and-ocr

Detect every screen state in a video (slides, cards, pages, popups) including flash cards that appear for only about a second, ignore mouse pointers, camera tiles, live badges and chat panels, link bullet-by-bullet builds, mark scrolling and playback, save one clean frame per state, OCR images in proper reading order on CPU, and recover burned-in subtitles with their on-screen times as SRT. Use whenever text lives in pixels: short videos, tutorials, lectures, screen recordings, livestream replays, lyric videos and MVs, film subtitles, screenshots, whiteboard photos, scanned pages.

What is screen-and-ocr?

Screen-and-OCR is a technical skill for developers who need to programmatically extract and understand every visual state in a video, especially when text is embedded in pixels. Unlike uniform frame sampling (which is based on luck), this skill detects distinct screen states—stable shots, flash cards appearing for only 1 second, dynamic scrolling segments, and bullet-by-bullet builds—by analyzing frame changes in real time using ffmpeg. It captures only one clean frame per state, ignoring mouse pointers, camera tiles, live badges, and chat panels. The skill then runs OCR (based on RapidOCR with ONNX on CPU) in proper reading order, applying conditional upscaling to improve accuracy on small text while avoiding known pitfalls. It also features a dedicated burned-in subtitle extraction module that uses background median or outline mode to isolate text from complex backgrounds, outputting SRT files with on-screen times. Built for tutorials, short videos, lectures, screen recordings, live stream replays, lyric MVs, film subtitles, and scanned documents, this skill ensures no fleeting textual information is missed.

Works with✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/handsomeZR-netizen/solve-everything/tree/HEAD/skills/screen-and-ocr

Installed? Explore more Image skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

screen-and-ocr: See Every State on Screen

Many critical pieces of information appear only on screen, and only momentarily: promotional codes and prices flashing in short videos, formulas on a single slide, tooltip popups. Uniform frame sampling is gambling; capturing frames based on visual changes is seeing every state.

1. Screen State Detection: slide_changes.py

python ${CLAUDE_SKILL_DIR}/scripts/slide_changes.py clip.mp4 --out slides/ \
    --crop 0,0,1280,620          # Only the content area: exclude subtitle bars, platform watermarks, comment sections
    --mask 1104,8,160,90         # Regions to ignore: camera thumbnails, live corner badges, stickers (repeatable)
    [--fps 2] [--settle 1.0] [--area 0.012]

How it works:

  • Streams 192 px wide grayscale thumbnails from ffmpeg; memory usage does not grow with video length.
  • A frame is considered "changing" only if more than --area (default 1.2%) pixels change. Mouse pointers, blinking dots do not trigger.
  • The screen must be still for --settle seconds to enter a new stable state; if the new frame looks the same as the previous one (e.g., a popup appears and disappears), the segment is not split.
  • Flashing: During transitions, as long as there is a continuous plateau of ≥ 2 identical samples that are different from both the preceding and following frames, it is marked as a flash state, separately captured and OCRed. Previous versions only recognized stable states, so two 1-second cards were dropped entirely—this is why this rule was added.
  • Continuous changes exceeding --dynamic seconds (scrolling, playback) are recorded as dynamic segments, with a sample frame taken every --dyn-every seconds.
  • New content appearing only on a previously blank background, and covering a small area, is judged as a bullet-by-bullet build (build) on the same page, linked by the same group. The frame with complete: true has the most content.
  • For stable states, the last frame before the change is saved (most complete during builds); for flashes, the midpoint of the plateau.

The sampling rate determines the shortest flash that can be caught: 2 fps (default) catches ≥ 1 second flashes; for shorter, use --fps 4.

Tested on (examples/short-video, 50 seconds, two 1-second flashes, a constant red dot in the upper right corner): only 7 frames were captured, but 7/7 states were obtained; uniform 16-frame sampling only caught 1/2 flashes, and 8-frame sampling caught none.

2. OCR: ocr.py

python ${CLAUDE_SKILL_DIR}/scripts/ocr.py --segments slides/segments.json   # Fill in OCR for every state (including flashes)
python ${CLAUDE_SKILL_DIR}/scripts/ocr.py shot1.png shots/ --out ocr.json

Built on top of RapidOCR (ONNX version of PaddleOCR, CPU only):

  • Conditional upscaling: First, recognize at original size. If the result is weak (no text, or minimum confidence < 0.8) and the short side < 720, upscale 2x and recognize again, selecting the result with the higher average confidence. Two pitfalls discovered: 30 px subtitle text could not be detected at all after upscaling; correctly recognized "12月6日20:00" at 1x turned into "12月6日日2 20:00" after upscaling, introducing more errors. Hence, selection cannot be based on number of recognized characters.
  • Reading order: Groups bounding boxes by vertical proximity into lines, sorts lines by horizontal order. When a vertical column gap is detected, reads the left column first, then the right; cross-column headers are placed first.
  • Boxes with confidence < 0.5 are discarded and counted.
  • Compatible with both the old package rapidocr_onnxruntime and the new package rapidocr (different interfaces). Pin the version when reproducing experiments.

3. Burned-in Subtitles: burned_subs.py

python ${CLAUDE_SKILL_DIR}/scripts/burned_subs.py clip.mp4 --crop 0,620,1280,100 --out subs/
python ${CLAUDE_SKILL_DIR}/scripts/burned_subs.py film.mp4 --crop 0,600,1280,120 --mode outline --fps 8 --out subs/
  • median mode: The subtitle background is taken as the per-pixel median of the entire video; pixels that are "brighter than the background and have a large difference" are considered glyphs. Suitable for static or slowly changing backgrounds, such as talking head videos, lyric MVs, static covers.
  • outline mode: Only bright pixels that are immediately adjacent to a dark outline or shadow are considered glyphs. Suitable for movie/TV content with moving backgrounds.
  • If the IoU of glyph masks between adjacent frames is below 0.5, a new subtitle line is assumed, allowing segmentation even without gaps. For each line, the frame with the most text pixels (fully faded in) is selected for OCR.
  • Outputs subs.json, subs.srt, and a composite image every 20 lines (screenshot + time + recognized text).

Tested: 7/7 subtitle lines segmented correctly, but 3 OCR errors: "帧" recognized as "顿", one extra "与", one missing "没". Therefore, subtitle OCR cannot be used as ground truth alone; timeline-fusion will compare it word-by-word with speech transcription.

For fancy fonts, italics, or text with shadows, you need to create custom masks. For example, white italic text on a white wall with a gray shadow: look for pixels that have a shadow 2–4 pixels below and to the right as glyphs, then remove spectral lines growing from the bottom edge. This is more effective than swapping OCR models.

Pitfall Checklist

  • Crop first, then analyze: Subtitle bars, watermarks, comment sections, camera thumbnails are all detected as visual changes. Use --crop and --mask to exclude them.
  • Scrolling is not page turning: Scrolling web pages or documents are recorded as dynamic segments; just examine their sample frames, do not OCR every frame.
  • OCR cannot understand graphics: Charts, flowcharts, handwriting, UI in screenshots—directly pass the image to a vision model.
  • Proper nouns on screen are authoritative: Titles, product names, person names displayed on screen are usually correct and can be used to correct speech transcription. When in doubt, use speech-to-text/scripts/score_candidates.py to verify.
  • Embedded subtitle tracks: If input-audit or media-ingest reports a subtitle track, extract it directly; do not use OCR.

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

Related Skills