Describing Video Frames with BLIP: What Captions Add and What They Miss
BLIP turns an image into a short English sentence. Run on frames sampled from a video, it gives you descriptions that can mention things an object detector has no class for, such as a flag, a space suit or a wooden surface. The same freedom means a sentence can also contain things that are not there, and a set of per-frame sentences says nothing reliable about actions or order.
This article explains how BLIP produces a caption, shows real captions beside detector labels for the same frames, and demonstrates how much one generation setting changes the result. The package discussed is AI-Powered Video Analyzer, a Python video analysis workflow that captions the frames it samples; behaviour refers to version 1.1.0, checked on 27 November 2026. It uses Salesforce/blip-image-captioning-base, which is BLIP, not the later BLIP-2.
Labels, captions and masks answer different questions
| Task | Output | Vocabulary | Where is it? | Typical question |
|---|---|---|---|---|
| Object detection | Boxes with a class and score | Fixed list of classes | Yes, a box | Which of these classes appear, and where? |
| Image captioning | One sentence | Open text | No | What would a person write about this picture? |
| Segmentation | A pixel mask per region or object | Fixed list or none | Yes, to the pixel | Exactly which pixels belong to it? |
The analyzer's default detector, D-FINE, can only choose among the 80 COCO classes. A caption model chooses words one at a time from its tokenizer vocabulary of about 30,000 word pieces. The caption has no boxes and no calibrated confidence per statement.
How BLIP turns an image into a sentence
Image encoder and text decoder
The captioning checkpoint has two parts. A Vision Transformer (ViT-B/16) reads the image: it is resized to 384 x 384 pixels, cut into 16 x 16 patches, giving 576 patches plus one class token, and passed through 12 layers that produce a 768-number vector for each. A text decoder, also 12 layers, then writes the sentence. Each of its layers uses causal self-attention over the words written so far and cross-attention over the image vectors.
From one video frame to one caption
Five stages in order: a frame is resized to 384 by 384 and normalised, a Vision Transformer encodes it as 577 vectors, a text decoder attends to those vectors while predicting one token at a time, beam search keeps five partial sentences, and the best one is turned into text.
| stage | input | output | what happens |
|---|---|---|---|
| 1. Prepare the frame | sampled frame, BGR | tensor [1, 3, 384, 384] | Converted to RGB, resized to a square and normalised with fixed channel means and standard deviations. |
| 2. Vision Transformer | tensor [1, 3, 384, 384] | 577 vectors of 768 | 24 x 24 patches of 16 pixels plus one class token, 12 layers. |
| 3. Text decoder | image vectors and words so far | next-token probabilities | 12 layers with causal self-attention and cross-attention to the image. |
| 4. Beam search | token probabilities | best of 5 partial sentences | Repeats token by token until an end token, subject to the length settings. |
| 5. Clean the text | token ids | caption string | Special tokens are removed and the analyzer drops a word repeated immediately. |
Stage 1 of 5, Prepare the frame. Input: sampled frame, BGR. Output: tensor [1, 3, 384, 384].
Conditional language generation
Write the image as v and a caption as tokens y_1, ..., y_T. The decoder models the probability of the sentence given the image as a product of one-token steps:
p(y_1, ..., y_T | v) = product over t = 1..T of p( y_t | y_1, ..., y_(t-1), v )
Each factor is a softmax over the vocabulary. Nothing in this expression refers to truth: it is high for sentences that are likely captions for images like this one, given the training data.
Training is not inference
During pre-training, BLIP optimises three objectives: an image-text contrastive loss that pulls matching image and text representations together, an image-text matching loss that classifies a pair as matching or not, and a language-modelling loss, the cross-entropy of the decoder's next-token predictions. The paper also introduces CapFilt, in which a captioner writes synthetic captions for web images and a filter removes noisy ones to produce better training data. The checkpoint used here is the variant that the model card describes as pretrained on COCO captions.
At inference time none of those losses is computed and nothing is learned. The analyzer calls generate() on each frame with these settings:
| Setting | Value | Effect |
|---|---|---|
num_beams |
5 | Beam search keeps the five best partial sentences |
max_length |
60 | Hard upper limit in tokens |
min_length |
20 | The end token is forbidden before 20 tokens |
repetition_penalty |
1.05 | Slightly lowers the score of tokens already used |
length_penalty |
0.6 | Divides a beam's log-probability by length^0.6, a milder length normalisation than the library default of 1.0 |
There is no text prompt. Each frame is captioned alone, one at a time, and a repeated adjacent word is removed afterwards.
Real captions beside detector labels
The test video is nine seconds long: three still photographs (public domain and CC0, from the scikit-image sample set) with a slow pan, three seconds each. The analyzer sampled nine frames and ran the balanced detector (dfine-s) and BLIP on each, on a Linux machine with a CUDA GPU, with Transformers 5.24.1 and PyTorch 2.15.0.
| Time | Detector labels (score 0.3 or more) | BLIP caption, verbatim |
|---|---|---|
| 0-1 s | person, bowl, clock | a woman in an orange space suit standing in front of an american flag with a space shuttle in the background |
| 2 s | person, bowl, clock, refrigerator | same sentence |
| 3-5 s | cat | a close up of a cat ' s face with green eyes and white whised whiss |
| 6 s | diningtable, spoon, cup, bowl | a cup of coffee sitting on top of a red saucer on a wooden table with a spoon |
| 7 s | diningtable, spoon, cup, bowl | a cup of coffee sitting on top of a red saucer next to a spoon on a wooden table |
| 8 s | diningtable, spoon, cup | a cup of coffee sitting on top of a red saucer with a spoon in front of it |
Detector labels and captions on the same three scenes
A nine second timeline with one row for detector labels and one for captions. In the first three seconds the detector reports person, bowl, clock and refrigerator while the caption describes a woman, a space suit, a flag and a shuttle. Cat and coffee scenes follow.
| lane | holds |
|---|---|
| Detector labels | person, bowl, clock, fridge |
| BLIP caption | woman, suit, flag, shuttle |
| event | lane | time |
|---|---|---|
| person, bowl, clock, fridge | Detector labels | 0 to 3 s |
| cat | Detector labels | 3 to 6 s |
| table, spoon, cup, bowl | Detector labels | 6 to 9 s |
| woman, suit, flag, shuttle | BLIP caption | 0 to 3 s |
| cat face, green eyes | BLIP caption | 3 to 6 s |
| coffee, red saucer, spoon | BLIP caption | 6 to 9 s |
At 0 s. Detector labels: person, bowl, clock, fridge. BLIP caption: woman, suit, flag, shuttle.
Three observations follow from looking at the frames themselves.
Captions mention things outside the label list. The space suit, the American flag, the shuttle, the cat's eyes, the saucer and the coffee have no COCO class. All are visible.
The detector reported things the caption does not, and some are wrong. On the first scene, bowl and clock share one box that outlines the metal neck ring of the suit; refrigerator, on one frame, covers nearly the whole picture. The caption mentions none of these. That agrees with what a person sees, but the caption did not remove or correct anything: the three false labels are still in the report.
A caption's silence proves nothing either. On the last frame the table is visible and detected, yet the sentence does not mention it.
Counting agreement
To put numbers on it, the next block counts, for each frame, which detector labels the caption names. The word matching is a choice made by hand (for instance, "woman" counts as naming person).
# one recorded run: dfine-s labels with score >= 0.3, and the BLIP caption, per sampled frame
astronaut = "a woman in an orange space suit standing in front of an american flag with a space shuttle in the background"
cat = "a close up of a cat ' s face with green eyes and white whised whiss"
frames = {
0: ({"person", "bowl", "clock"}, astronaut),
1: ({"person", "bowl", "clock"}, astronaut),
2: ({"person", "bowl", "clock", "refrigerator"}, astronaut),
3: ({"cat"}, cat), 4: ({"cat"}, cat), 5: ({"cat"}, cat),
6: ({"diningtable", "spoon", "cup", "bowl"},
"a cup of coffee sitting on top of a red saucer on a wooden table with a spoon"),
7: ({"diningtable", "spoon", "cup", "bowl"},
"a cup of coffee sitting on top of a red saucer next to a spoon on a wooden table"),
8: ({"diningtable", "spoon", "cup"},
"a cup of coffee sitting on top of a red saucer with a spoon in front of it"),
}
# which caption words count as naming a detector label (a choice made here, by hand)
names = {"person": {"person", "man", "woman"}, "diningtable": {"table"}, "refrigerator": {"fridge", "refrigerator"}}
total = named_total = 0
for second, (labels, caption) in frames.items():
words = set(caption.split())
named = {label for label in labels if names.get(label, {label}) & words}
total, named_total = total + len(labels), named_total + len(named)
print(f"{second} s: named {sorted(named)} not named {sorted(labels - named)}")
print(f"{named_total} of {total} label-frame pairs are named in the caption")
0 s: named ['person'] not named ['bowl', 'clock']
1 s: named ['person'] not named ['bowl', 'clock']
2 s: named ['person'] not named ['bowl', 'clock', 'refrigerator']
3 s: named ['cat'] not named []
4 s: named ['cat'] not named []
5 s: named ['cat'] not named []
6 s: named ['cup', 'diningtable', 'spoon'] not named ['bowl']
7 s: named ['cup', 'diningtable', 'spoon'] not named ['bowl']
8 s: named ['cup', 'spoon'] not named ['diningtable']
14 of 24 label-frame pairs are named in the caption
Of the ten pairs not named, seven are the false labels on the portrait, two are a bowl reported on the cup, and one is a correct diningtable the sentence omitted. Disagreement is therefore a useful flag for review, not a verdict about which side is right. With three pictures, none of these counts measures how often either model is correct.
Where the sentences go wrong
The same three photographs were also captioned directly, uncropped, with the analyzer's settings. Each result was identical over three runs.
| Image | Caption, verbatim | Problems visible in the image |
|---|---|---|
| Astronaut portrait | a young man in an orange space suit holding a helmet and a space shuttle in front of an american flag | The portrait is of a woman. Nobody is holding a space shuttle; a shuttle model stands behind her. |
| Cat close-up | a close up of a cat ' s face with green eyes and long whised whis | "whised whis" is not a word |
| Coffee cup | a cup of coffee sitting on top of a red saucer with a spoon in it ' s mouth | Nothing has a mouth; the spoon lies on the saucer |
One caption of the uncropped portrait, checked claim by claim
A caption splits into five claims. Orange space suit and American flag are confirmed by the picture although neither is a COCO class. Helmet is visible. Young man is wrong, and holding a space shuttle is wrong because the shuttle is a model standing behind the person.
| box | arrows to | detail |
|---|---|---|
| Generated caption | orange space suit: seen; american flag: seen; helmet: seen; young man: wrong; holding a shuttle: wrong | One sentence for the whole photograph. |
| orange space suit: seen | — | — |
| american flag: seen | — | — |
| helmet: seen | — | — |
| young man: wrong | — | — |
| holding a shuttle: wrong | — | The shuttle is a model on a stand behind the person. |
6 boxes and 5 arrows. No box is selected.
Note that one photograph was captioned "a woman" when cropped and rescaled inside the video and "a young man" at full size: a different framing changed what the model asserted about a person. Do not use captions to infer gender, age, identity or anything else about people.
The frames of the video also show a subtler problem. The first caption says the person is "standing", but the frame shows only head and shoulders. Posture is a guess that reads like an observation.
How much one setting matters
The min_length of 20 forbids the decoder from stopping early. To see what that does, the same frames and photographs were captioned again with every analyzer setting except min_length (same checkpoint and library versions).
| Input | With min_length=20 (analyzer) |
Without min_length |
|---|---|---|
| Portrait at 0 s, in video | a woman in an orange space suit standing in front of an american flag with a space shuttle in the background | a woman in an orange space suit standing in front of an american flag |
| Cat, in video | a close up of a cat ' s face with green eyes and white whised whiss | a close up of a cat with green eyes |
| Coffee at 6 s, in video | a cup of coffee sitting on top of a red saucer on a wooden table with a spoon | a cup of coffee sitting on top of a wooden table |
| Portrait, uncropped | a young man in an orange space suit holding a helmet and a space shuttle in front of an american flag | a man in an orange space suit holding a helmet |
| Coffee, uncropped | a cup of coffee sitting on top of a red saucer with a spoon in it ' s mouth | a cup of coffee sitting on top of a wooden table |
On these images, forcing longer sentences added both detail and errors. The non-words, the spoon's "mouth" and the held shuttle disappear without the constraint, but so do the saucer and the spoon, and the wrong "man" stays. Five rows cannot tell you which setting is better for your footage. They do show that a caption depends on decoding choices as well as on the picture, so record those choices with the output. The analyzer has no option to change them.
Why captions do not describe the video
Each caption sees one frame. The decoder receives no earlier frame, no timestamp and no earlier sentence. Consequently:
- Actions are not established. "Standing", "sitting" or "holding" are read from a single instant. Whether someone is entering or leaving needs more than one frame and a model that relates them.
- Order and change are not described. Three identical sentences can mean that nothing changed or that the model could not see the change.
- Continuity is not tracked. "A man" in two captions need not be the same man.
- Coverage follows sampling. Only sampled frames are captioned; anything between them has no sentence at all.
The caption stage also does not talk to the detector. It does not check, change or complete detections, and detections do not guide the sentence.
| Reasonable use | Unsafe use |
|---|---|
| Searching a long recording for frames worth opening | Concluding that an event happened or did not happen |
| Adding context words that a fixed label list lacks | Correcting detector labels automatically |
| Drafting notes that a person will check | Describing people's attributes or identity |
| Comparing with labels to flag frames for review | Reporting counts or exact positions |
How to verify a caption
- Open the frame. The report gives
frame_indexandtimestamp_secfor every caption. - Split the sentence into separate claims: objects, attributes, relations, actions.
- Check each claim against the image. Treat actions and posture as unverified unless several frames support them.
- Compare with detector labels. Agreement is weak support, since both can be wrong; disagreement marks a frame to look at.
- Look for mechanical faults: broken words, repetitions, an odd ending. Here they appeared where the model was forced to keep writing.
- Record the model, library versions and generation settings.
Running the captions yourself
Through the analyzer
git clone https://github.com/arashsajjadi/ai-powered-video-analyzer.git
cd ai-powered-video-analyzer
python -m pip install -r pip_requirements.txt
python -m pip install -e . # the requirements file does not install the analyzer
ai-video-analyzer analyze video.mp4 --no-audio-events --no-summarization -o results
Captions appear in the JSON report under captions, each with its frame index, time and text; --no-captioning switches the stage off. Speech transcription still runs in this command if the audio can be extracted. BLIP chooses a GPU by itself if one is available, whatever --device says. If BLIP cannot be loaded, the caption list is simply empty and the report's limitations list does not say why. If you use the summary stage, it receives only the first five captions.
Directly with Transformers
This script captions about one frame per second without the analyzer. It uses beam search and no minimum length.
import cv2
import torch
from PIL import Image
from transformers import BlipForConditionalGeneration, BlipProcessor
MODEL = "Salesforce/blip-image-captioning-base"
processor = BlipProcessor.from_pretrained(MODEL) # first use downloads the weights
model = BlipForConditionalGeneration.from_pretrained(MODEL).eval()
def caption(frame_bgr, **generation):
image = Image.fromarray(cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB))
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
ids = model.generate(**inputs, **generation)
return processor.decode(ids[0], skip_special_tokens=True)
video = cv2.VideoCapture("video.mp4")
step = max(1, round(video.get(cv2.CAP_PROP_FPS))) # about one frame per second
index = 0
while True:
ok, frame = video.read()
if not ok:
break
if index % step == 0:
print(f"frame {index:4d}: {caption(frame, num_beams=5, max_length=60)}")
index += 1
video.release()
On the test clip (CPU, Transformers 5.24.1) it printed:
frame 0: a woman in an orange space suit standing in front of an american flag
frame 30: a woman in an orange space suit standing in front of an american flag
frame 60: a woman in an orange space suit standing in front of an american flag
frame 90: a close up of a cat with green eyes
frame 120: a close up of a cat with green eyes
frame 150: a close up of a cat with green eyes
frame 180: a cup of coffee sitting on top of a wooden table
frame 210: a cup of coffee sitting on top of a wooden table
frame 240: a cup of coffee sitting on top of a wooden table
| Item | Verified value |
|---|---|
| Model id | Salesforce/blip-image-captioning-base (revision 82a3776) |
| Classes used | BlipProcessor, BlipForConditionalGeneration |
| Needs | torch, transformers, Pillow, OpenCV |
| First download observed | About 1.98 GB with Transformers 5.24.1 (two copies of the weights) |
| Licence on the model card | BSD-3-Clause; the card also states the release is for research purposes only, in support of an academic paper |
Read both statements on the card before using the model commercially. This is not legal advice.
How the detector labels beside these captions are produced is explained in D-FINE object detection on video frames.
What happens when captions and labels are handed to a language model is covered in local video summarization with Ollama.
To use detected objects and their relations as inputs to a model rather than as text, see the scene graph recipes.
References
- J. Li, D. Li, C. Xiong, S. Hoi. BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation. arXiv:2201.12086
- Salesforce.
blip-image-captioning-basemodel card. Hugging Face - Hugging Face Transformers, text generation settings. Documentation
- A. Sajjadi. AI-Powered Video Analyzer, source repository, version 1.1.0. GitHub