AI Video Inpainting Engine - remove watermarks and objects from video using SAM 2 + ProPainter
Project description
Ghost Remover
AI-powered video inpainting engine. Remove watermarks, logos, and objects from video using SAM 2 + ProPainter.
Features
- SAM 2 tracking - Segment anything with text, box, or point prompts via Grounding DINO + SAM 2
- ProPainter inpainting - Temporal-aware video inpainting with optical flow completion
- Two-pass architecture - Pass 1: tracking + mask generation. Pass 2: inpainting + streaming encode
- Chunked processing - Handles arbitrarily long videos with overlap blending
- MPS optimized - Native Apple Silicon support with automatic CPU fallback for unsupported ops
- Checkpoint resume - Interrupt and resume without losing progress
- Batch processing - Process multiple videos in one command
- Quality metrics - Temporal consistency, pixel integrity (PSNR), and style (LPIPS) checks
v0.3 Performance Upgrades
| Optimization | Effect |
|---|---|
| Eliminate redundant ffprobe | frames_to_numpy accepts video_info param, skips re-probing |
| Single decode in Pass 1 | Reuses extracted JPEGs for re-detection fallback instead of second FFmpeg decode |
| Float16 mixed precision | torch.autocast("mps", float16) for ProPainter inference — ~1.5x faster, half memory |
| Chunk prefetch | Background thread decodes next chunk while current chunk is being inpainted |
| Vectorized blending | Overlap blending uses numpy batch ops instead of per-frame Python loop |
| OOM auto-retry | On memory error: split chunk in half → retry → downscale fallback → original frames |
| FFmpeg timeout | All subprocess calls have timeout protection (120-300s) |
| Frame count validation | Warns when decoded frame count doesn't match expected |
Installation
# Create conda environment
conda env create -f environment.yml
conda activate ghost-remover
# Clone ProPainter into third_party/
git clone https://github.com/sczhou/ProPainter.git third_party/ProPainter
bash setup_propainter.sh
# Download SAM 2 checkpoints
mkdir -p checkpoints
# See https://github.com/facebookresearch/segment-anything-2#download-checkpoints
Usage
CLI
# Basic - remove watermark by text prompt
ghost-remover remove --video input.mp4 --target "watermark"
# With bounding box
ghost-remover remove --video input.mp4 --target "logo" --box 100,50,300,150
# Dry-run (preview mask overlay only)
ghost-remover remove --video input.mp4 --target "watermark" --dry-run
# Batch processing
ghost-remover remove --video a.mp4 b.mp4 c.mp4 --target "watermark"
# Hardware-accelerated encoding (VideoToolbox)
ghost-remover remove --video input.mp4 --target "watermark" --hw-accel
# Adjust sensitivity (0.1=tight, 1.0=aggressive)
ghost-remover remove --video input.mp4 --target "watermark" --sensitivity 0.7
Python API
from main import GhostRemoverPipeline
config = {
"video_path": "input.mp4",
"target": "watermark",
"sensitivity": 0.5,
"sam_model_size": "large",
}
pipeline = GhostRemoverPipeline(config)
output = pipeline.run()
pipeline.cleanup()
Architecture
ghost-remover/
core/
ffmpeg_handler.py # Video decode/encode, streaming pipe I/O
tracker_sam3.py # SAM 2 segmentation + video tracking
inpainter_pp.py # ProPainter inpainting engine
utils/
gpu_manager.py # MPS memory monitoring + chunk size estimation
video_chunker.py # Chunk planning + overlap blending
checkpoint.py # Interrupt recovery
quality_metrics.py # Temporal/pixel/style quality checks
api/
skill_interface.py # CLI + JSON API
main.py # Two-pass pipeline orchestrator
Pipeline Flow
Input Video
│
├─ Pass 1: SAM 2 Tracking (5-50%)
│ ├─ First frame segmentation (text/box/point prompt)
│ ├─ Per-chunk mask propagation
│ ├─ Drift detection + re-detection
│ └─ Packed mask storage (.npz)
│
├─ Pass 2: ProPainter Inpainting (50-95%)
│ ├─ RAFT optical flow (fp16)
│ ├─ Bidirectional flow completion
│ ├─ Image propagation
│ ├─ Transformer inpainting (sliding window)
│ ├─ Overlap blending (vectorized)
│ └─ Streaming FFmpeg encode
│
└─ Finalize (95-100%)
├─ Audio merge
└─ Quality check
Tests
# Run all tests (134 tests)
python3 -m pytest tests/ghost-remover/ -v
Requirements
- Python >= 3.11
- PyTorch >= 2.2.0 (MPS support)
- FFmpeg
- SAM 2 (segment-anything-2)
- ProPainter (third_party/)
- Grounding DINO (via HuggingFace transformers, optional for text prompts)
Version
v0.3.0 — 134 tests passing
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ghost_remover-0.3.1.tar.gz
(24.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ghost_remover-0.3.1.tar.gz.
File metadata
- Download URL: ghost_remover-0.3.1.tar.gz
- Upload date:
- Size: 24.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8017a7b07e17c4aaa0b10b07c75a72098b6e750e482151594eb0b4abc18c6f9e
|
|
| MD5 |
e7016bd09753d01c8d9601c1a677f2ef
|
|
| BLAKE2b-256 |
4d7f3a62aaf8661d3b232545b215418b2a3340c64bf0e9e3dd008e21e879c8bb
|
File details
Details for the file ghost_remover-0.3.1-py3-none-any.whl.
File metadata
- Download URL: ghost_remover-0.3.1-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad18989d51ca15c801a6e370cb14d2ba574e6fc1d8e5f5f1e8f8979a276b2045
|
|
| MD5 |
377e8b32b1145b8d1e712c383493b5cc
|
|
| BLAKE2b-256 |
1705ecd2c38bcc7bbed7d4c462a04dc8f3a97b920106f5dc221640a25feb13ef
|