VideoQuery is a semantic video-search backend for the question: “Where in this video does this appear?” Upload a video, search in plain language, and receive the matching keyframes with timestamps.
For example, search for:
a person holding a phonea red car entering the framea slide with a bar charta worker wearing a hard hat
VideoQuery is designed for teams that need to find a visual moment without manually scrubbing through long recordings: product and user-research footage, support calls, security video, event recordings, media libraries, or internal demos.
Search terms: semantic video search, natural-language video search, CLIP video retrieval, visual search, keyframe search, video intelligence pipeline.
- Accepts a video upload through a FastAPI endpoint.
- Splits a long video into time-based chunks.
- Extracts sampled frames from each chunk in parallel.
- Embeds frames with CLIP and indexes them as vectors.
- Embeds a text query with the same model and retrieves the nearest visual matches.
- Returns the matching frame, score, and exact video timestamp so a client can jump directly to the relevant moment.
flowchart LR
A["Upload video"] --> B["S3 / local storage"]
B --> C["Splitter: ffprobe + time chunks"]
C --> D["SQS / local queue"]
D --> E["Parallel workers"]
E --> F["FFmpeg sampled frames"]
F --> G["CLIP image embeddings"]
G --> H["OpenSearch k-NN index"]
I["Natural-language query"] --> J["CLIP text embedding"]
J --> H
H --> K["Top keyframes + timestamps"]
The system is built around the operational problem of searching long videos at scale:
- Parallel video processing: a lightweight splitter uses
ffprobeto determine duration, then publishes independent time-range tasks such as0–60s,60–120s, and120–180s. - Worker isolation: each worker downloads and processes only its assigned interval, avoiding a single long-running process for the full video.
- Semantic retrieval: CLIP places images and text in the same vector space, allowing a text description to retrieve visually related frames.
- Production-oriented storage: frames are retained in object storage and indexed in OpenSearch as
knn_vectordocuments with timestamps and source metadata. - Local-to-cloud path: the same interfaces support a deterministic local backend for plumbing tests and an AWS path using S3, SQS, OpenSearch, Lambda, or containerized workers.
| Layer | Implementation |
|---|---|
| API | FastAPI upload and search endpoints |
| Video metadata | ffprobe duration probing |
| Frame sampling | ffmpeg, configurable sampling FPS |
| Work distribution | SQS in AWS; JSONL-backed queue locally |
| Embeddings | OpenCLIP in semantic mode; deterministic hash provider for tests |
| Vector search | OpenSearch k-NN in AWS; JSONL-backed cosine search locally |
| Object storage | S3 in AWS; filesystem storage locally |
| Infrastructure | AWS SAM template and Docker worker image |
VideoQuery requires Python 3.11+ and ffmpeg / ffprobe on your PATH.
git clone https://github.com/GuoShuyin/VideoQuery.git
cd VideoQuery
python3.11 -m venv .venv
. .venv/bin/activate
pip install -e ".[clip,dev]"
# macOS
brew install ffmpeg
export VIDEOQUERY_BACKEND=local
export VIDEOQUERY_LOCAL_AUTOPROCESS=true
export VIDEOQUERY_EMBEDDING_BACKEND=clip
uvicorn videoquery.api:app --reloadIn a second terminal, upload a video and query it:
curl -F "file=@/path/to/video.mp4" http://127.0.0.1:8000/videos
curl "http://127.0.0.1:8000/search?q=person%20holding%20a%20phone&k=5"The search response includes each candidate's timestamp, similarity score, and frame_s3_key.
The default local embedding provider is hash. It is deterministic, fast, and useful for testing upload, queuing, indexing, and retrieval wiring—but it is not semantic search. Set VIDEOQUERY_EMBEDDING_BACKEND=clip to perform real text-to-frame retrieval.
The AWS reference stack is defined in infra/aws-sam.yaml:
- An S3
ObjectCreatedevent invokes the splitter function. - The splitter publishes chunk tasks to SQS.
- Workers consume tasks, sample frames, store them in S3, and index embeddings in OpenSearch.
- For large videos or CLIP model warmup, the worker can run in ECS/Fargate using
docker/worker.Dockerfile.
Configure the AWS backend through environment variables. See .env.example for the expected names.
Uploads a video and either queues its chunks or processes them immediately in local auto-process mode.
curl -F "file=@/path/to/video.mp4" http://127.0.0.1:8000/videosSearches indexed video frames with a natural-language query.
curl "http://127.0.0.1:8000/search?q=red%20car&k=5"Example response shape:
{
"query": "red car",
"results": [
{
"video_id": "b7a2...",
"chunk_id": "000001",
"timestamp": 73.0,
"score": 0.82,
"frame_s3_key": "frames/b7a2/000001/frame_000014_73.000.jpg"
}
]
}src/videoquery/api.py: FastAPI upload and search endpoints.src/videoquery/ingest.py: S3-event splitter and chunk-task creation.src/videoquery/worker.py: worker processing, embedding, storage, and indexing.src/videoquery/video.py:ffprobeduration probing andffmpegframe extraction.src/videoquery/embeddings.py: CLIP embedding provider and deterministic local fallback.src/videoquery/search.py: OpenSearch and local vector stores.infra/aws-sam.yaml: AWS reference infrastructure.docker/worker.Dockerfile: container image for worker deployments.
PYTHONPATH=src python3.11 -m unittest discover -s testsThe unit tests cover time-range chunking, deterministic embedding behavior, and local cosine-similarity retrieval.
- A higher sampling FPS increases recall but also storage, inference, and indexing cost.
- CLIP returns visually relevant candidate frames; applications may add reranking, tracking, or temporal grouping for stronger end-user results.
- The repository is a backend reference implementation. A production product would typically add a browser UI, signed frame URLs, authentication, retention policies, and monitoring.
Do not commit private footage, personal data, or copyrighted video without permission. Use synthetic or fully authorized sample videos for demos.