Nodes for searching videos by motion
MotionVideoSearch is a Python project for extracting motion-based embeddings from videos and storing them in a vector database (FAISS). You can then quickly search those embeddings with an input image, retrieving matching segments of the indexed videos. It offers:
Video Ingestion
Slice videos into small segments, generate motion-based embeddings for each segment, and store them in FAISS for fast similarity search.
Search
Query the index with a single motion image to find relevant video segments, returning top matches ranked by distance in vector space.
Concurrency Support
Organize indexing jobs in different subdirectories, then merge (combine) them later into one big index.
Watermark Removal (Optional)
If you clone l-comm/WatermarkRemoval, you can automatically detect and remove watermarks from video frames during ingestion.
ComfyUI Nodes
Includes two custom nodes:
IG_MotionVideoSearch
: Takes an image input and returns the top 5 ranked URLs from the FAISS index.IG_MotionVideoFrame
: Converts 24 consecutive frames into a single “dot frame,” which encodes motion features in a color-coded image.We have some ComfyUI nodes ready to be used with a pre-existing video database consisting of roughly 100,000 videos. You can get started using the following workflow: MotionSearch
So for example, this video
https://github.com/user-attachments/assets/3195c170-e080-498f-be09-a06db53d1a73
Will give the following search results
https://github.com/user-attachments/assets/b793af91-882c-44ea-8dc7-c051a73f74b2
https://github.com/user-attachments/assets/ca9008aa-281e-47c5-aff9-05ebce8fe43a
https://github.com/user-attachments/assets/dc7fd9da-1e62-49e1-98cf-9acd64f025bf
Clone the repository:
git clone https://github.com/IDGallagher/MotionVideoSearch
cd MotionVideoSearch
(Optional) Create a conda environment:
conda create -n mvs python=3.9
conda activate mvs
Install PyTorch and TorchVision compatible with your CUDA setup (example below uses CUDA 11.8):
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Install ffmpeg 6.x:
conda install -c conda-forge ffmpeg=6.*
Install other dependencies:
pip install tqdm matplotlib einops einshape scipy timm lmdb av mediapy typer imageio imageio-ffmpeg requests opencv-python
Install Faiss (version example below):
conda install -c pytorch faiss-cpu=1.9.0
(Optional) Download the watermark removal repo if you want that functionality:
git clone https://github.com/l-comm/WatermarkRemoval.git
After installing, you can run the CLI commands via `python main.py [COMMAND] [OPTIONS]`.
Use the `store` command to process videos and store their embeddings in the FAISS index:
python main.py store \
--dir /path/to/videos \
--max-time 1.0 \
--debug
You can also process a CSV file of URLs:
python main.py store \
--csv path/to/videos.csv \
--max-time 1.0 \
--start-entry 1
Once you have stored some embeddings, you can search with:
python main.py search \
--image ./query.jpg \
--top_k 5
This compares the motion image `query.jpg` against the FAISS index and returns the top 5 matches with their URLs, metadata, and distance.
If you used the concurrency feature (`--concurrent-store`) to generate multiple subindexes, you can combine them all:
python main.py combine
This searches for numbered directories under `./data` that each contain `index.faiss`, merges them, and writes a final combined `index.faiss` in `./data`.
To create multiple indexes in subdirectories, use:
python main.py store --concurrent-store
Each run will create (or use) a new numbered subdirectory under `./data`. You can specify a subdirectory with `--concurrent-index 3` to store in `./data/3/`, for example. Later, use `combine` to merge them.
If you want to use the motion search in ComfyUI, simply:
Contributions and suggestions are welcome! Feel free to open issues or pull requests for enhancements or bug fixes.
This project is licensed under the MIT License. Please see the LICENSE file for details.