https://github.com/nadermx/backgroundremover Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} nadermx / backgroundremover Public * * Notifications * Fork 279 * Star 2.9k Background Remover lets you Remove Background from images and video using AI with a simple command line interface that is free and open source. backgroundremoverai.com License MIT license 2.9k stars 279 forks Star Notifications * Code * Issues 10 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights nadermx/backgroundremover This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 9 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/n] Use Git or checkout with SVN using the web URL. [gh repo clone naderm] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @nadermx nadermx Merge remote-tracking branch 'origin/main' into main ... 1c4ceff May 6, 2023 Merge remote-tracking branch 'origin/main' into main 1c4ceff Git stats * 92 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github Create FUNDING.yml July 30, 2021 20:56 backgroundremover fix imports May 5, 2023 15:18 dist Add whl May 6, 2023 10:07 examplefiles rename directory March 30, 2022 16:50 models Create license May 5, 2023 22:02 .editorconfig initial July 5, 2021 16:45 LICENSE.txt initial July 5, 2021 16:45 MANIFEST.in initial July 5, 2021 16:45 README.md Update README.md May 5, 2023 22:04 pyproject.toml initial July 5, 2021 16:45 requirements.txt Update requirements.txt May 5, 2023 20:32 setup.cfg initial July 5, 2021 16:45 setup.py I think this fixes it May 5, 2023 15:51 View code [ ] BackgroundRemover Requirements How to install torch and fmpeg Installation Installation Usage as a cli Image Advance usage for image background removal Video remove background from video and make transparent mov remove background from local video and overlay it over other video remove background from local video and overlay it over an image remove background from video and make transparent gif Make matte key file (green screen overlay) Advance usage for video Todo Pull requests If you like this library bitcoin Reason for project References License README.md BackgroundRemover Background Remover background remover video BackgroundRemover is a command line tool to remove background from image and video, made by nadermx to power https:// BackgroundRemoverAI.com. If you wonder why it was made read this short blog post. Requirements * python >= 3.6 * python3.6-dev #or what ever version of python you using * torch and torchvision stable version (https://pytorch.org) * ffmpeg 4.4+ How to install torch and fmpeg Go to https://pytorch.org and scroll down to INSTALL PYTORCH section and follow the instructions. For example: PyTorch Build: Stable (1.7.1) Your OS: Windows Package: Pip Language: Python CUDA: None To install ffmpeg and python-dev sudo apt install ffmpeg python3.6-dev Installation To run code without installation: python -m backgroundremover.cmd.cli -i "video.mp4" -mk -o "output.mov" and for windows python.exe -m backgroundremover.cmd.cli -i "video.mp4" -mk -o "output.mov" Installation To Install backgroundremover, install it from pypi pip install --upgrade pip pip install backgroundremover Please note that when you first run the program, it will check to see if you have the u2net models, if you do not, it will pull them from this repo Usage as a cli Image Remove the background from a local file image backgroundremover -i "/path/to/image.jpeg" -o "output.png" Advance usage for image background removal Sometimes it is possible to achieve better results by turning on alpha matting. Example: backgroundremover -i "/path/to/image.jpeg" -a -ae 15 -o "output.png" change the model for diferent background removal methods between u2netp, u2net, or u2net_human_seg backgroundremover -i "/path/to/image.jpeg" -m "u2net_human_seg" -o "output.png" Video remove background from video and make transparent mov backgroundremover -i "/path/to/video.mp4" -tv -o "output.mov" remove background from local video and overlay it over other video backgroundremover -i "/path/to/video.mp4" -tov "/path/to/videtobeoverlayed.mp4" -o "output.mov" remove background from local video and overlay it over an image backgroundremover -i "/path/to/video.mp4" -toi "/path/to/videtobeoverlayed.mp4" -o "output.mov" remove background from video and make transparent gif backgroundremover -i "/path/to/video.mp4" -tg -o "output.gif" Make matte key file (green screen overlay) Make a matte file for premier backgroundremover -i "/path/to/video.mp4" -mk -o "output.matte.mp4" Advance usage for video Change the framerate of the video (default is set to 30) backgroundremover -i "/path/to/video.mp4" -fr 30 -tv -o "output.mov" Set total number of frames of the video (default is set to -1, ie the remove background from full video) backgroundremover -i "/path/to/video.mp4" -fl 150 -tv -o "output.mov" Change the gpu batch size of the video (default is set to 1) backgroundremover -i "/path/to/video.mp4" -gb 4 -tv -o "output.mov" Change the number of workers working on video (default is set to 1) backgroundremover -i "/path/to/video.mp4" -wn 4 -tv -o "output.mov" change the model for diferent background removal methods between u2netp, u2net, or u2net_human_seg and limit the frames to 150 backgroundremover -i "/path/to/video.mp4" -m "u2net_human_seg" -fl 150 -tv -o "output.mov" Todo * convert logic from video to image to utilize more GPU on image removal * clean up documentation a bit more * add ability to adjust and give feedback images or videos to datasets * add ability to realtime background removal for videos, for streaming * finish flask server api * add ability to use other models than u2net, ie your own. * other Pull requests Accepted If you like this library Give a link to our project BackgroundRemoverAI.com or this git, telling people that you like it or use it. bitcoin bc1q80pshgqgqr7wn3kax59xwvmgq9ftvwla7dew7w Reason for project We made it our own package after merging together parts of others, adding in a few features of our own via posting parts as bounty questions on superuser, etc. As well as asked on hackernews earlier to open source the image part, so decided to add in video, and a bit more. References * https://arxiv.org/pdf/2005.09007.pdf * https://github.com/NathanUA/U-2-Net * https://github.com/pymatting/pymatting * https://github.com/danielgatis/rembg * https://github.com/ecsplendid/rembg-greenscreen * https://superuser.com/questions/1647590/ have-ffmpeg-merge-a-matte-key-file-over-the-normal-video-file-removing-the-backg * https://superuser.com/questions/1648680/ ffmpeg-alphamerge-two-videos-into-a-gif-with-transparent-background /1649339?noredirect=1#comment2522687_1649339 * https://superuser.com/questions/1649817/ ffmpeg-overlay-a-video-after-alphamerging-two-others/1649856# 1649856 License * Copyright (c) 2021-present Johnathan Nader * Copyright (c) 2020-present Lucas Nestler * Copyright (c) 2020-present Dr. Tim Scarfe * Copyright (c) 2020-present Daniel Gatis Code Licensed under MIT License Models Licensed under Apache License 2.0 About Background Remover lets you Remove Background from images and video using AI with a simple command line interface that is free and open source. backgroundremoverai.com Topics python video pytorch photo-editing video-editing background-removal remove-background remove-background-image background-remover backgroundremover removebackground remove-background-video Resources Readme License MIT license Stars 2.9k stars Watchers 31 watching Forks 279 forks Report repository Releases 9 BackgroundRemover v0.2.1 Latest May 5, 2023 + 8 releases Sponsor this project Sponsor Learn more about GitHub Sponsors Packages 0 No packages published Used by 16 * @isayahc * @Pranav-Kunjir * @Steve-Shambles * @kudrikmed * @istorykorea * @Yizhi-Zhang * @hazel-gallery * @caio-vinicius + 8 Contributors 3 * @nadermx nadermx Johnathan Nader * @by321 by321 * @edouard-mangel edouard-mangel Languages * Python 100.0% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.