Ffmpeg ocr logo

From damionrashford/media-os · View interactive version

Ffmpeg ocr logo is an AI agent skill from the GitHub repository damionrashford/media-os. OCR, logo detection, and rectangle operations with ffmpeg: ocr (Tesseract inside ffmpeg), find_rect (find a reference rectangle), cover_rect (hide it), delogo and removelogo (station logo removal), qrencode (generate QR), quirc (decode QR from frames). Use when the user asks to read text from video

How to use this skill

Skill file

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

When to use

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 -

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

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

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_rect=object=ref.pgm:threshold=0.3,cover_rect=mode=blur

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:

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

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

Reference docs

Gotchas

Examples

Example 1 — OCR a news ticker every second

ffmpeg -i news.mp4 \
  -vf "fps=1,ocr=datapath=/usr/local/share/tessdata/:language=eng,metadata=mode=print:file=ticker.txt" \
  -an -f null -
grep "^lavfi.ocr.text=" ticker.txt

fps=1 samples 1 frame per second before OCR to cut cost by 24–30x.

Example 2 — Remove a broadcaster bug in the top-right

First locate the bug coordinates with show=1:

ffplay -vf "delogo=x=1720:y=40:w=180:h=80:show=1" live.mp4

Then render the cleaned file:

ffmpeg -i live.mp4 \
  -vf "delogo=x=1720:y=40:w=180:h=80" \
  -c:v libx264 -crf 20 -c:a copy clean.mp4

Example 3 — Auto-blur a recurring reference object

Wherever the reference image appears, blur it.

# Prepare gray8 reference
magick ref.png -colorspace gray ref.pgm

# Auto-blur
ffmpeg -i surveil.mp4 \
  -vf "find_rect=object=ref.pgm:threshold=0.4,cover_rect=mode=blur" \
  -c:v libx264 -crf 20 -c:a copy blurred.mp4

Example 4 — Decode QR codes once per second

ffmpeg -i tracer.mp4 -vf "fps=1,quirc,metadata=mode=print:file=qr.log" -an -f null -
grep "payload=" qr.log

Example 5 — Embed a tracking QR code bottom-right

ffmpeg -i in.mp4 \
  -vf "qrencode=text='job-id=12345':q=128:x=w-q-20:y=h-q-20:level=Q:\
foreground_color=black:background_color=white@0.85" \
  -c:v libx264 -crf 20 -c:a copy out.mp4

Troubleshooting

Error: `No such filter: 'ocr'`

Cause: Your ffmpeg build doesn't include libtesseract.

Solution: Check with ffmpeg -filters | grep ocr. Reinstall (brew reinstall ffmpeg — Homebrew's default is full-featured) or build from source with --enable-libtesseract. Alternatively, extract frames with ffmpeg-frames-images and run tesseract directly.

Error: `Failed to init ocr (Failed loading language 'eng')`

Cause: Tessdata missing or datapath wrong.

Solution: Verify the folder exists and contains eng.traineddata: ls /usr/local/share/tessdata/. On macOS also install brew install tesseract. Pass the correct path via datapath=.

OCR output is gibberish / empty

Cause: Source video too compressed, text too small, or font antialiased too aggressively.

Solution: Sample at higher resolution, pre-scale (scale=iw*2:ih*2:flags=lanczos), pre-contrast (eq=contrast=1.4), or crop to the text region first (crop=W:H:X:Y). For best accuracy, extract frames and run tesseract standalone.

`delogo` leaves a visible smear

Cause: Logo extends beyond the specified rectangle, or is textured.

Solution: Widen w/h by 4–8 pixels, then set band=2. For textured logos try removelogo with a mask PNG instead.

`removelogo: Mask file does not match video size`

Cause: Mask PNG resolution differs from the video stream resolution.

Solution: Resize the mask to match: magick mask.png -resize 1920x1080! mask_fixed.png. Must be an exact match.

`find_rect` never matches

Cause: Reference image not in gray8, or threshold too strict.

Solution: Confirm gray8: ffprobe -show_streams ref.pgm | grep pix_fmt should say gray. Relax threshold (0.5 → 0.7). Reduce the reference to a tight crop of the logo — extra border content kills correlation score.

`No such filter: 'quirc'` / `'qrencode'`

Cause: ffmpeg built without libquirc / libqrencode.

Solution: Confirm with ffmpeg -filters | grep -E 'quirc|qrencode'. Either rebuild with --enable-libquirc --enable-libqrencode (FFmpeg 7.1+ only), or fall back to zbarimg (decode) / qrencode CLI (encode) on extracted frames.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.