View Source Code
Browse the complete example on GitHub
d1.2. It works for anything you can describe, such as license plates, faces, or logos.
d1 answers a boxes question on each sampled frame and returns a box around every match in a single call. There is no detector to train, and a few hundred lines of Python turn the per-frame boxes into smooth blurs. The 32-second demo clip takes 162 calls and costs about one cent.

d1.3-ultra. The tutorial uses the cheaper d1.2 by default. See the --model option in step 4. Clip: People on Beach by Fábio Reis de Abreu, Pexels License.
Prerequisites
You need the following to run this example:- Python 3.10+ and uv
- ffmpeg (on macOS:
brew install ffmpeg) - Liquid API key (create one at console.liquid.ai under Dashboard > API Keys)
- Video clip to blur (the demo uses People on Beach by Fábio Reis de Abreu, free to use under the Pexels License)
Quickstart
1. Clone the repository
The code for this example is available in the Liquid AI cookbook repository. Clone it with:2. Add your API key
Copy the template and setLIQUID_API_KEY in the new .env file:
3. Download the demo clip
Download the beach clip from Pexels asbeach.mp4 into the video-blur folder:
4. Blur the clip
Blur everyone in swimwear and keep people in street clothes sharp:How to build a video blur tool with decision models
The whole demo is a single Python file,blur.py. Its pipeline has five steps. Only step 2 calls the model. The other steps are geometry and video plumbing.
Step 1: Sample frames
Sending every frame of a 60 fps video would be slow and expensive, and objects barely move between neighboring frames. Thedecisions() function starts by asking ffmpeg for --fps frames per second (5 by default), saved as JPEG files in a temporary folder.:
decide() function then opens each frame and shrinks it to at most 1280 pixels wide (WIDTH) before sending it. Image tokens scale with the pixel count, so a 1280-pixel frame costs about half as much as a full 1080p frame:
Step 2: Ask d1 for boxes
Each sampled frame goes to the decision API in a single request. Besides classification question types such as Noul, Choice, and Score, d1 has two question types that locate objects in a picture:
This example uses boxes, since a frame can hold any number of things to blur. To build the request, the
questions() function turns every --blur and --keep description into a named boxes question. The ask() function then posts the frame, Base64-encoded, and the questions to the Liquid API, and waits and retries if the API answers 429 (too many requests at once). For a full API reference, see the d1 documentation.
For the beach demo, each request looks like this (the Base64 image is shortened):
left, right) and height (top, bottom), measured from the top-left corner. As a result, the same box works on the downscaled frame sent to the API and on the full-resolution frame you blur.
The model answers all the questions in one call, and the image is billed only once per request. Adding a second --blur with another wording therefore costs only the extra question’s tokens. It can catch objects that one wording misses, but test it: a broader wording such as “Every person close to the camera …” can also return one box around two people sitting side by side.
The frames are independent, so decisions() sends them in parallel, 16 at a time (WORKERS).
Step 3: Choose the boxes to blur in each frame
Thechosen() function merges the answers from step 2 into the final list of boxes to blur for that frame. It goes through the blur boxes from largest to smallest and drops a box when:
- It’s a speck. The box is under 6 pixels wide or tall.
- It’s a duplicate. The box overlaps a box that’s already kept, usually because two
--blurwordings found the same thing, or the model returned two boxes for one person. - A
--keepquestion boxed it. The box overlaps a box from a--keepquestion.
--keep as a counterweight. A broad --blur description has good recall but also boxes some things you want to leave sharp. A --keep description of those things removes them without making the --blur wording narrower.
Step 4: Link boxes into tracks
Per-frame boxes flicker: an object found in four frames is sometimes missed in the fifth, and a spurious box can appear for one frame. Blurring the raw boxes would flash on and off. Thelinked() function connects the boxes across frames into one track per object:
- Each live track predicts where its object is in the current frame from its last box and its velocity.
- Every pair of track and new box gets a score, its IoU with the prediction. A box that moved past its predicted position still matches if it’s nearby and about as tall.
- Pairs are matched greedily from the best score down. Unmatched boxes start new tracks, and a track unseen for more than
GAP(0.5 seconds) ends.
smoothed() function then keeps a track only if it’s reliable:
Step 5: Render the blurred video
The output keeps the original frame rate, so most output frames fall between two sampled frames. For each output frame, theat() function interpolates every track’s box linearly between its two nearest sightings. It also starts the blur slightly before the first sighting (PRE) and holds it after the last one (POST), fading in and out over FADE seconds:
paint() function builds the blur by downscaling the frame 14×, blurring it, and scaling it back up. It then pastes this blurred frame through a mask of rounded rectangles, padded slightly around each box and feathered at the edges. Finally, render() streams raw frames from ffmpeg, paints them in a thread pool, and pipes them back into ffmpeg to encode H.264, copying the original audio track.
Limits
- It processes a finished clip. Tracking looks ahead and behind in time, so the script reads the whole clip before it renders. For a live stream, you would need to process the video in short chunks and add a delay of about a second.
- Cost grows with the clip. It grows linearly with
--fps, the number of questions, and the clip length, and the frame size sets the image tokens per call. See Image Token Usage for the formula. - The sampled frames are sent to the Liquid API. To keep footage on your machine, run an open-weight decision model such as d1-2B locally. It also answers
boxesquestions, but you need to replace the API call inask().
Need help?
Join our Discord
Connect with the community and ask questions about this example.