File size: 6,488 Bytes
7645257 0ee293e cd851c0 76b6368 0401b51 76b6368 cd851c0 b109571 76b6368 cd851c0 0ee293e 9a027a2 0ee293e dd579a3 0ee293e e9f466f 0ee293e e9f466f 0ee293e 76b6368 0ee293e e9f466f 76b6368 e9f466f 0ee293e e9f466f 0ee293e e9f466f 0ee293e e9f466f 0ee293e e9f466f 0ee293e 76b6368 0ee293e e9f466f 0ee293e e9f466f 0ee293e dd579a3 76b6368 b109571 0ee293e b109571 76b6368 b109571 76b6368 0ee293e 76b6368 0ee293e b109571 0ee293e dd579a3 0ee293e dd579a3 0ee293e e9f466f 0ee293e e9f466f 0ee293e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | ---
title: BackgroundFX Pro - SAM2 + MatAnyone
emoji: π¬
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.42.0
app_file: app.py
pinned: false
license: mit
suggested_hardware: t4-small
suggested_storage: small
---
# π¬ BackgroundFX Pro - SAM2 + MatAnyone
**Professional AI video background replacement with state-of-the-art segmentation and alpha matting**
Powered by **SAM2** (Meta's Segment Anything Model 2) and **MatAnyone** (CVPR 2025) for Hollywood-quality video background replacement with professional alpha matting.
## β¨ Key Features
- **π€ SAM2 Integration**: State-of-the-art object segmentation from Meta
- **π MatAnyone Professional Matting**: CVPR 2025 video matting with memory propagation
- **β‘ Smart Pipeline**: SAM2 segmentation β MatAnyone refinement β Perfect compositing
- **π¨ Background Options**: 8 built-in presets + custom image upload
- **πΎ Memory Optimized**: Lazy loading with automatic cleanup
- **π± Professional UI**: Clean interface with real-time progress tracking
## π Quick Start
1. **Upload Video**: Drag & drop your video (MP4, AVI, MOV, MKV, WebM - max 5 minutes)
2. **Choose Background**: Select from presets or upload custom image
3. **Select Quality**: Choose SAM2 model size and MatAnyone settings
4. **Process**: Click "Create Professional Video" and wait for magic
5. **Download**: Get your Hollywood-quality result!
## π― Professional Pipeline
### **Stage 1: SAM2 Segmentation**
- Meta's Segment Anything Model 2 detects and segments the main subject
- Multiple model sizes: Tiny (38MB), Small (185MB), Base (320MB)
- Smart point selection for optimal segmentation
### **Stage 2: MatAnyone Alpha Matting**
- CVPR 2025 state-of-the-art video matting
- Memory-based propagation for stable boundaries
- Professional hair and edge detail preservation
- Target-assigned matting using SAM2 masks
### **Stage 3: Professional Compositing**
- Seamless background replacement
- Advanced edge smoothing and blending
- Cinema-quality output
## π§ Technical Specifications
### **AI Models**
- **SAM2**: Meta's Segment Anything Model 2 for object detection
- **MatAnyone**: CVPR 2025 video matting with consistent memory propagation
- **Processing**: Lazy loading, CUDA optimization, memory management
### **Supported Formats**
- **Input**: MP4, AVI, MOV, MKV, WebM
- **Resolution**: Up to 1920x1080 (Full HD)
- **Duration**: Max 5 minutes on free tier
- **Output**: High-quality MP4 with professional alpha compositing
## β‘ Performance Guide
| Hardware | SAM2 Only | SAM2 + MatAnyone | Recommended Use |
|----------|-----------|------------------|-----------------|
| CPU | 3-5 min/video min | 6-10 min/video min | Quick tests only |
| T4-small | 45-90s/video min | 90-180s/video min | β **Recommended** |
| T4-medium+ | 30-60s/video min | 60-120s/video min | **Professional** |
## π¨ Background Presets
Choose from 8 professional presets:
- **π Ocean Blue** - Clean professional gradient
- **π
Sunset Orange** - Warm and vibrant atmosphere
- **π² Forest Green** - Natural and calming backdrop
- **π Purple Haze** - Creative and modern aesthetic
- **βͺ Pure White** - Minimal and clean
- **β« Pure Black** - Dramatic high-contrast
- **π Chroma Green** - For further video editing
- **π Chroma Blue** - Alternative chroma key
## π¬ Professional Use Cases
- **π― Content Creation**: Remove distracting backgrounds for professional videos
- **πΉ Virtual Production**: Custom backgrounds for video calls and streaming
- **π Education**: Clean, professional backgrounds for instructional content
- **π± Social Media**: Eye-catching backgrounds that increase engagement
- **πͺ Entertainment**: Creative backgrounds for artistic and commercial projects
## π οΈ Advanced Settings
### **SAM2 Model Selection**
- **Tiny**: Fastest processing, good quality (recommended for quick previews)
- **Small**: Balanced speed and quality (recommended for most use cases)
- **Base**: Best quality, slower processing (recommended for final videos)
### **MatAnyone Options**
- **Professional Mode**: Full MatAnyone processing for cinema-quality results
- **Fast Mode**: SAM2-only processing for quick turnaround
### **Edge Enhancement**
- **Edge Smoothing**: 0-5 scale for softer subject boundaries
- **Memory Propagation**: Automatic temporal consistency across frames
## ποΈ Built With
- [**SAM2**](https://github.com/facebookresearch/segment-anything-2) - Meta's Segment Anything Model 2
- [**MatAnyone**](https://github.com/pq-yang/MatAnyone) - CVPR 2025 Video Matting Framework
- [**Gradio**](https://gradio.app/) - Machine learning web interface framework
- [**OpenCV**](https://opencv.org/) - Computer vision and video processing
- [**PyTorch**](https://pytorch.org/) - Deep learning framework
## π System Requirements
- **Recommended**: GPU-enabled Space (T4-small or better)
- **Minimum**: CPU-only mode supported but significantly slower
- **Memory**: Automatic management with CUDA optimization
- **Storage**: No persistent storage needed (true lazy loading)
## π¬ Research Citations
```bibtex
@InProceedings{yang2025matanyone,
title = {{MatAnyone}: Stable Video Matting with Consistent Memory Propagation},
author = {Yang, Peiqing and Zhou, Shangchen and Zhao, Jixin and Tao, Qingyi and Loy, Chen Change},
booktitle = {CVPR},
year = {2025}
}
@article{ravi2024sam2,
title = {SAM 2: Segment Anything in Images and Videos},
author = {Ravi, Nikhila and Gabeur, Valentin and Hu, Yuan-Ting and Hu, Ronghang and Ryali, Chaitanya and Ma, Tengyu and Khedr, Haitham and RΓ€dle, Roman and Rolland, Chloe and Gustafson, Laura and Mintun, Eric and Pan, Junting and Alwala, Kalyan Vasudev and Carion, Nicolas and Wu, Chao-Yuan and Girshick, Ross and DollΓ‘r, Piotr and Feichtenhofer, Christoph},
journal = {arXiv preprint arXiv:2408.00714},
year = {2024}
}
```
## π Links
- **Project Website**: [BackgroundFX Pro Demo](https://huggingface.co/spaces/your-username/backgroundfx-pro)
- **SAM2 Repository**: [facebookresearch/segment-anything-2](https://github.com/facebookresearch/segment-anything-2)
- **MatAnyone Repository**: [pq-yang/MatAnyone](https://github.com/pq-yang/MatAnyone)
- **Configuration Reference**: [HF Spaces Config](https://huggingface.co/docs/hub/spaces-config-reference)
---
**Ready to create professional videos with AI?** Upload your video and experience the future of background replacement! π |