Ffmpeg Ocr Logo
Context: $ARGUMENTS
OCR, logo removal, and QR operations inside ffmpeg are filter-graph operations. They run on the decoded frame, emit results as frame metadata under lavfi.<filter>.*, and/or modify pixels in place. All are re-encode only — you cannot stream-copy through any of these filters.
Several of the filters in this skill are build-flag gated — ocr needs --enable-libtesseract, quirc needs --enable-libquirc, and qrencode needs --enable-libqrencode. Many static / minimal ffmpeg builds ship without these. Always check the build first (Step 1) before writing a pipeline.
Quick start
- Read text from video: → Step 1 (check
ocr) → Step 2 (pick "OCR") → Step 3 - Hide a known rectangle (e.g. bug/logo at fixed coords): → Step 2 (pick "delogo") → Step 3
- Remove a logo with an alpha mask PNG: → Step 2 (pick "removelogo") → Step 3
- Find and hide a recurring graphic (reference image): → Step 2 (pick "find-rect + cover-rect") → Step 3
- Decode QR codes from frames: → Step 1 (check
quirc) → Step 2 (pick "QR decode") → Step 3 - Burn a QR code overlay into video: → Step 1 (check
qrencode) → Step 2 (pick "QR encode") → Step 3
When to use
- Extracting burned-in text (lower-thirds, scoreboard tickers, timestamps) live from a stream.
- Removing a broadcaster bug / channel logo from a captured feed.
- Blurring license plates or faces at a consistent screen location.
- Embedding / reading QR watermarks for pipeline tracing or ad-insertion cues.
Not this skill: Pre-recorded high-accuracy OCR — extract frames with ffmpeg-frames-images then run tesseract directly for better accuracy. True object detection / face detection — use an external ML model. Arbitrary watermark removal without a known shape — ffmpeg has no generic inpainting.
Step 1 — Check your ffmpeg build
Run once before building any pipeline:
ffmpeg -hide_banner -filters 2>/dev/null | grep -E "ocr|find_rect|cover_rect|delogo|removelogo|qrencode|quirc"
Or use the helper:
uv run ${CLAUDE_SKILL_DIR}/scripts/ocrlogo.py check-build
Expected results:
| Filter | Build flag required | Usually present? |
|---|---|---|
| ocr | --enable-libtesseract | Homebrew yes; static builds often no |
| find_rect | (core) | Yes |
| cover_rect | (core) | Yes |
| delogo | (core, GPL — --enable-gpl) | Yes on GPL builds |
| removelogo | (core) | Yes |
| qrencode | --enable-libqrencode | Rare, FFmpeg 7.1+ only |
| quirc | --enable-libquirc | Rare, FFmpeg 7.1+ only |
If a filter is missing, either rebuild ffmpeg with the flag or fall back to the OS tool (tesseract, zbarimg, qrencode CLI) on extracted frames.
Step 2 — Pick the operation
A. OCR — read text from frames
ffmpeg -i in.mp4 \
-vf "ocr=datapath=/usr/local/share/tessdata/:language=eng,metadata=mode=print:file=ocr.txt" \
-an -f null -
datapathis the Tesseract tessdata directory (containseng.traineddataetc.). If omitted, ffmpeg uses Tesseract's compile-time default.metadata=mode=print:file=ocr.txtdumpslavfi.ocr.textfor every frame. Without it, results stay in memory and are lost.- Add
-anto skip audio,-f null -to discard video output. - Whitelist / blacklist characters via
whitelist=0123456789:(useful for clocks) andblacklist=....
OCR a single frame at 10s:
ffmpeg -ss 10 -i in.mp4 -vframes 1 \
-vf "ocr=datapath=/usr/local/share/tessdata/,metadata=mode=print" \
-f null - 2>&1 | grep "lavfi.ocr.text"
B. delogo — erase a known rectangle
ffmpeg -i in.mp4 \
-vf "delogo=x=10:y=10:w=200:h=80:show=0" \
-c:v libx264 -crf 20 -c:a copy out.mp4
x,yis the top-left of the rectangle;w,hits size.show=1draws a green outline — use when tuning coordinates, then set back to0.- The rectangle is filled by interpolating the 1-pixel ring just outside it. Works well on solid colors, poorly on textured or semi-transparent logos.
- If edges bleed, extend the clearing zone via
band=2(default 1).
C. removelogo — erase via alpha-mask PNG
ffmpeg -i in.mp4 \
-vf "removelogo=logo_mask.png" \
-c:v libx264 -crf 20 -c:a copy out.mp4
- The mask must be the same resolution as the video.
- White (255) = logo pixel to remove; Black (0) = keep untouched. This is opposite of the typical alpha convention.
- Build the mask by screen-grabbing a black frame showing the logo, thresholding in GIMP/ImageMagick, then eroding once or twice.
D. find-rect + cover-rect — find a reference image and hide it
# ref.pgm must be gray8 (convert via ImageMagick: magick ref.png -colorspace gray ref.pgm)
ffmpeg -i in.mp4 \
-vf "find_rect=object=ref.pgm:threshold=0.3,cover_rect=cover=blank.jpg:mode=cover" \
-c:v libx264 -crf 20 -c:a copy out.mp4
find_rectscans each frame for the reference sub-image via cross-correlation. The matched rectangle's position is written tolavfi.rect.{x,y,w,h,score}.cover_rectreads those metadata entries from its upstream filter — they must be in the same filter chain.cover=image must be yuv420 (e.g. a plain.jpg). Usemode=blurfor a soft blur instead of an image patch:
find_rect=object=ref.pgm:threshold=0.3,cover_rect=mode=blur
- Tune
threshold(0.01 = exact match, 0.99 = almost anything). Start at 0.3–0.5. - Restrict search area with
xmin/ymin/xmax/ymaxfor speed. discard=1drops frames where no match was found (useful when you only want the detection hits).
E. QR decode (`quirc`)
ffmpeg -i in.mp4 \
-vf "quirc,metadata=mode=print" \
-an -f null - 2>&1 | grep "lavfi.quirc"
Emitted metadata per frame with a detected QR:
lavfi.quirc.count=N(only set if ≥ 1 found)lavfi.quirc.0.payload=<decoded text>lavfi.quirc.0.corner.0.x…lavfi.quirc.0.corner.3.y(four corner coords)
F. QR encode (`qrencode`) — overlay QR on video
ffmpeg -i in.mp4 \
-vf "qrencode=text='https://example.com':q=w*0.25:x=w-q-20:y=20:level=H" \
-c:v libx264 -crf 20 -c:a copy out.mp4
textortextfilesupplies the payload.qrcode_width/qis the rendered size (accepts expressions referencingw,h).x,yposition the top-left corner — same expression DSL asoverlay/drawtext.levelis L/M/Q/H (H = most redundancy, larger code).foreground_color/background_colortake any ffmpeg color name.
Step 3 — Run the command and parse the metadata
When you use metadata=mode=print, ffmpeg emits a block per frame to stdout (or the file set by file=):
frame:42 pts:42000 pts_time:1.68
lavfi.ocr.text=Hello World
lavfi.ocr.confidence=87 91 93
Parse with regex:
import re
OCR_RE = re.compile(r"^lavfi\.ocr\.text=(.*)$", re.M)
QR_RE = re.compile(r"^lavfi\.quirc\.(\d+)\.payload=(.*)$", re.M)
RECT_RE = re.compile(r"^lavfi\.rect\.(x|y|w|h|score)=([\d.]+)$", re.M)
Or use the helper script:
uv run ${CLAUDE_SKILL_DIR}/scripts/ocrlogo.py ocr --input in.mp4 --output ocr.txt
uv run ${CLAUDE_SKILL_DIR}/scripts/ocrlogo.py qr-decode --input in.mp4
uv run ${CLAUDE_SKILL_DIR}/scripts/ocrlogo.py find-cover --input in.mp4 --output o.mp4 \
--reference logo.pgm --cover blur
Available scripts
scripts/ocrlogo.py— subcommands:check-build,ocr,delogo,removelogo,find-cover,qr-decode,qr-encode. Stdlib only. Supports--dry-runand--verbose.