A Next.js app that uploads video to blob storage and calls fal.ai SAM endpoints for image/video segmentation.
Overview
This project provides a UI for:
- uploading a video file, then running full-video segmentation
- using the webcam for “near real-time” per-frame segmentation (sampling every 5th frame)
Segmentation work is performed by fal.ai models, and uploads are stored via Vercel Blob.
Core Concepts
Upload blob URL
app/api/upload-video/route.tsaccepts multipart upload and writes the bytes to blob storage via@vercel/blob.Frame segmentation (image)
app/api/segment-frame/route.tsuploads a JPEG frame to fal storage and callsfal-ai/sam-3/image.Video segmentation (SAM2 vs SAM3)
app/api/segment-video/route.tschooses:fal-ai/sam-3/videowhenmodel === "sam3"fal-ai/sam2/videootherwise
and returns the fal result payload.
Client loop + overlay rendering
app/page.tsx:- draws video frames into a canvas
- periodically POSTs frames to
/api/segment-frame - draws a semi-transparent overlay (if
data.image.urlis returned) and bounding boxes (fromdata.masks[].box).
Technology Stack
- Root: Next.js (App Router), React, TypeScript, Tailwind CSS
- Segmentation backend: fal.ai serverless client (
@fal-ai/serverless-client) - Storage: Vercel Blob (
@vercel/blob)
Getting Started
pnpm install
pnpm devScripts
build: next build
dev: next dev
lint: eslint .
start: next startRepository Layout
app/page.tsx: UI (upload/webcam + canvas overlay)app/api/upload-video/route.ts: blob uploadapp/api/segment-frame/route.ts: per-frame segmentationapp/api/segment-video/route.ts: full-video segmentation
Configuration
This repo expects credentials at runtime for:
process.env.FAL_KEY(used by fal.ai route handlers)- whatever environment configuration
@vercel/blobrequires for server-sideput().
Notes
- Keep this README factual and repository-grounded.