TGraphX › Insights › How AI Analyzes an Entire Video: From Frames to Timestamped Evidence
← Back to Insights

How AI Analyzes an Entire Video: From Frames to Timestamped Evidence

Topic: Vision, multimodal and domain applications

When a tool says it analyzed a whole video, it often did not run its models on every frame. A typical pipeline picks some frames, runs vision models on those, processes the audio as a separate stream and then, sometimes, asks a language model to write a summary of the resulting text. What you receive is evidence at particular times. It is not a record of everything that happened.

That difference decides what you may conclude. This article gives the arithmetic of what sampling can miss, three short scripts you can run, and a list of claims that each kind of analysis can and cannot support. The worked example is AI-Powered Video Analyzer, a local video analysis pipeline written in Python, at version v1.1.0 as checked on 2026-11-27. The reasoning applies to any sampled pipeline.

To install and run that example first, follow analyzing a video locally from install to first report.

A video is a sequence of timed frames

Write a video as an ordered list of frames, each with a time:

text
V = (I_0, t_0), (I_1, t_1), ..., (I_{N-1}, t_{N-1})

I_k is the image of frame k, t_k is the moment it is shown in seconds, and N is the number of frames. The audio track is a second signal on the same time axis, with its own sampling rate that has nothing to do with the frame rate.

For constant frame rate video with f frames per second and counting from zero, t_k = k / f. Frame 90 of a 30 fps file is shown at 3.0 s. Files from phones and screen recorders can have a variable frame rate instead, and then no single f maps indices to times. The correct value is the presentation timestamp stored for each frame, which ffprobe can list.

The following script builds a file that runs at 30 fps for two seconds and at 10 fps for the next two, then compares the two ways of computing time. It needs ffmpeg and ffprobe on the path.

python
import subprocess
import cv2

# 60 frames at 30 fps (2 s), then 20 frames at 10 fps (2 s), one variable-rate file.
subprocess.run([
    "ffmpeg", "-v", "error", "-y", "-f", "lavfi", "-i", "testsrc=size=160x120:rate=30",
    "-vf", "setpts='if(lt(N,60),N/30,2+(N-60)/10)/TB'", "-frames:v", "80",
    "-fps_mode", "vfr", "-c:v", "libx264", "-bf", "0", "-pix_fmt", "yuv420p", "vfr.mp4"], check=True)
probe = subprocess.run([
    "ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "frame=pts_time",
    "-of", "csv=p=0", "vfr.mp4"], capture_output=True, text=True, check=True)
pts = [float(line.strip(",")) for line in probe.stdout.split()]
cap = cv2.VideoCapture("vfr.mp4")
fps = cap.get(cv2.CAP_PROP_FPS)
cap.release()
print("frames", len(pts), "reported fps", round(fps, 3))
print("frame   k/fps   file timestamp   difference")
for k in (0, 30, 60, 70, 79):
    print(f"{k:5d} {k / fps:7.3f} {pts[k]:16.3f} {k / fps - pts[k]:12.3f}")

With ffmpeg 8.0.1 and OpenCV 5.1.0 this printed:

text
frames 80 reported fps 20.339
frame   k/fps   file timestamp   difference
    0   0.000            0.000        0.000
   30   1.475            1.000        0.475
   60   2.950            2.000        0.950
   70   3.442            3.000        0.442
   79   3.884            3.900       -0.016

One average rate cannot describe both halves, so the error grows and then shrinks, and in the middle of this four second file it is almost a full second. The analyzer computes timestamps as frame index divided by the reported rate; on a similar synthetic variable-rate clip its times were off by up to about 0.95 s. If you need to cite moments in such a file, look up each frame index in the ffprobe list, or convert the file to a constant rate first and record that you did.

How much of the video reaches a model

Two numbers describe a sampled analysis. With n selected frames out of N, over a duration of T seconds:

text
frame coverage     c = n / N
sampling density   rho = n / T      (selected frames per second)

In the analyzer's default run on a 9 s, 30 fps clip of three still photographs, 9 of 270 frames went to the detector: c is 3.3% and rho is 1 per second. On a 12 s synthetic clip with cuts and motion it selected 21 of 360 frames, 5.8%. In both cases every frame was decoded, because the sampler has to look at the pixels to choose. Decoding a frame and analyzing it are different things.

Strategy Frames given to models What can be missed Cost
Every frame N nothing the camera captured; the models can still err grows with frame rate and length
Fixed interval about T / D events shorter than the interval D, depending on timing predictable
Adaptive (change driven) depends on content changes below its threshold or inside its minimum spacing varies; rises with motion

Higher coverage costs more computation and does not by itself add understanding. A detector run on all frames still sees one image at a time.

Can an important event be missed?

Yes, and for fixed-interval sampling the odds are simple. Suppose samples are D seconds apart, an event is visible for d seconds, and the position of the sampling grid relative to the event is random and uniform. The samples sit at phase + mD, and at least one falls inside the event only if the phase lands in a stretch of length d within each period:

text
P(at least one sample inside the event) = min(1, d / D)

In frames, with an event of L frames and one sample every S frames, it is min(1, L / S). You can check this by trying every phase:

python
def hit_fraction(event_frames, step):
    """Share of sampling phases for which at least one sample lands inside the event."""
    event = range(1000, 1000 + event_frames)
    hits = sum(any(k % step == phase for k in event) for phase in range(step))
    return hits / step

fps, step = 30, 30                      # one sample per second
for length in (3, 10, 15, 30, 45):
    print(f"{length / fps:4.2f} s event: counted {hit_fraction(length, step):.3f}, "
          f"formula {min(1, length / step):.3f}")
text
0.10 s event: counted 0.100, formula 0.100
0.33 s event: counted 0.333, formula 0.333
0.50 s event: counted 0.500, formula 0.500
1.00 s event: counted 1.000, formula 1.000
1.50 s event: counted 1.000, formula 1.000

At one sample per second, an event is guaranteed a sample only if it lasts at least one second. A tenth of a second flash has one chance in ten. To guarantee a look at events of duration d, the largest gap between samples must not exceed d.

Being sampled is necessary and not sufficient. The detector may miss the object in the sampled frame or name it wrongly, so the probability that the event appears in your report is at most the probability that it was sampled. Several samples of a nearly identical image also do not give independent second chances.

Adaptive sampling changes the odds, not the logic

The analyzer's default strategy takes a regular sample about once per second and adds samples when consecutive frames differ strongly, subject to a minimum spacing. The formula above does not describe it, so measure. On the 12 s synthetic clip the results at v1.1.0 were:

  • A full-screen flash lasting three frames (0.1 s) received no sample. It began too soon after the previous one. The disappearance of the flash then triggered a sample labelled scene_change, which no longer showed any flash.
  • A hard cut at 9.0 s fell two frames after a sample, inside the minimum spacing. The first look at the new scene came at 9.93 s.
  • A small red square visible for a third of a second was sampled, only because a regular sample happened to fall inside it. Its pixel change was far too small to trigger anything.

Frames selected from a 12 second synthetic clip by adaptive sampling

ScenesstaticpandarkBrief eventsAdaptive samples024681012seconds
What each lane holds at the selected time
laneholds
Scenesdark
Brief eventsflash
Adaptive samplesno frame here (nearest at 10.267 s)
Events, with the sampled frames inside each visual event
eventlanetimeAdaptive samples
staticScenes0 to 2.967 sframe at 0, 1, 2 s
square movesScenes3 to 5.967 sframe at 3, 4, 5 s
panScenes6 to 8.967 sframe at 6, 6.267, 6.533 s and 9 more
darkScenes9 to 11.967 sframe at 9.933, 10.267, 11.267 s
flashBrief events10.167 to 10.233 smissed
red squareBrief events11.167 to 11.467 sframe at 11.267 s

Adaptive samples: 21 frames in 12 s (1.75 per second); visual events without a sampled frame: 1 of 6 (flash).

At 10.2 s. Scenes: dark. Brief events: flash. Adaptive samples: no frame here (nearest at 10.267 s).

Select a time to see whether any frame was analyzed there. The flash around 10.2 s has no sample inside it. Measured times and events, as recorded by the author: Analyzer v1.1.0 frame sampler, default adaptive strategy, 640x360 30 fps synthetic clip; OpenCV 5.1.0. The figure only displays and compares them. A frame shows a visual event when its time lies from the start to the end, both included.

Two other strategies on the same clip show that no choice is safe in general. A uniform one second grid misses both brief events. A strategy that samples only on large changes catches the flash at its first frame, and ignores the red square.

A short flash falls between uniform samples

Brief eventsUniform, 1 per secondOn large changes024681012seconds
What each lane holds at the selected time
laneholds
Brief eventsflash
Uniform, 1 per secondno frame here (nearest at 10 s)
On large changesa sampled frame
Events, with the sampled frames inside each visual event
eventlanetimeUniform, 1 per secondOn large changes
flashBrief events10.167 to 10.233 smissedframe at 10.167 s
red squareBrief events11.167 to 11.467 smissedmissed

Uniform, 1 per second: 12 frames in 12 s (1 per second); visual events without a sampled frame: 2 of 2 (flash, red square).

On large changes: 5 frames in 12 s (0.417 per second); visual events without a sampled frame: 1 of 2 (red square).

At 10.167 s. Brief events: flash. Uniform, 1 per second: no frame here (nearest at 10 s). On large changes: a sampled frame.

Dashed outlines mark the brief events that a row of samples missed. Measured times and events, as recorded by the author: Analyzer v1.1.0 frame sampler, uniform and scene_change strategies with default settings, same 12 s synthetic clip. The figure only displays and compares them. A frame shows a visual event when its time lies from the start to the end, both included.

How to choose and score the change metric behind such a rule is the subject of scene change detection in Python.

A check you can run yourself

This script writes a six second clip with three events, then asks the analyzer which of them received a sample. All models are disabled, so it needs no weights; it does need the package installed.

python
import cv2
import numpy as np
from ai_powered_video_analyzer.config import AnalysisConfig
from ai_powered_video_analyzer.core import analyze_video

EVENTS = {"flash": (65, 68), "small square": (100, 112), "dark block": (120, 180)}

writer = cv2.VideoWriter("events.avi", cv2.VideoWriter_fourcc(*"FFV1"), 30, (160, 120))
for k in range(180):                                    # 6 s at 30 fps
    frame = np.full((120, 160, 3), 128, np.uint8)
    if 65 <= k < 68:
        frame[:] = 255
    if 100 <= k < 112:
        frame[10:30, 10:30] = 255
    if k >= 120:
        frame[40:120, 20:140] = 20
    writer.write(frame)
writer.release()

for strategy in ("uniform", "adaptive"):
    report = analyze_video(AnalysisConfig(
        video_path="events.avi", output_dir=f"out_{strategy}", backend="none",
        frame_strategy=strategy, enable_captioning=False, enable_audio_events=False,
        enable_summarization=False, ollama_model="unused"))
    seen = {f["frame_index"]: f["timestamp_sec"] for f in report.frame_observations}
    print(f"{strategy}: {report.sampled_frame_count} of {report.frame_count} frames")
    for name, (start, stop) in EVENTS.items():
        inside = [seen[k] for k in sorted(seen) if start <= k < stop]
        print(f"  {name:12s} first sample inside: {inside[0] if inside else 'NONE'}")
print(report.limitations)
text
uniform: 6 of 180 frames
  flash        first sample inside: NONE
  small square first sample inside: NONE
  dark block   first sample inside: 4.0
adaptive: 7 of 180 frames
  flash        first sample inside: NONE
  small square first sample inside: NONE
  dark block   first sample inside: 4.0
['No objects detected (backend=null, model=null). Ensure model weights are available.', 'No audio track found in video.']

Both strategies miss the flash and the small square. The adaptive run has one frame more: it samples at 2.267 s, the first frame after the flash has gone, and its later regular samples shift accordingly. Note also what the limitations list says: that no detector ran and that there is no audio. Nothing warns that two events fell between samples, and no report can warn about something it never looked at. An event missing from a report is not evidence that it did not happen.

Different tasks support different claims

"Video analysis" covers tasks with very different outputs.

  • Per-frame object detection finds boxes with class labels in one image. It has no memory of other frames.
  • Sampled-frame analysis applies such per-image models to selected frames and lists the results with times.
  • Temporal event or action recognition classifies something that unfolds over time, such as a fall or a handover. It needs a model that looks across frames.
  • Tracking links detections across frames into identities. SORT, for instance, associates detector boxes using predicted motion and box overlap.
  • Multimodal evidence integration relates observations from images, speech and sound on a shared time axis.
Task Can support Cannot support
Per-frame detection "a box labelled person in the frame at 2.0 s" how long it stayed; whether it is the same person later
Sampled-frame analysis "labels seen at these sampled times" what happened between samples
Event recognition "this clip segment looks like the class X" events outside its class list or window
Tracking "these boxes belong to one track" identity beyond the tracker's errors; who someone is
Multimodal integration "these observations overlap in time" that one caused or describes the other

At v1.1.0 the analyzer does the first two, captions each sampled frame independently and transcribes speech. It has no tracking and no temporal event recognition. Ten person boxes in a report therefore mean ten boxes: one person seen ten times, ten people, or some of them duplicates or false detections.

How timestamps connect observations

To combine sources, give every observation the same shape:

text
(source, start_time, end_time, value)

A sampled frame is a point, with start equal to end. A speech segment and a sound window are intervals. A frame at time t lies within an interval if start <= t <= end, and two intervals a and b overlap if a.start < b.end and b.start < a.end. Overlap means that two things were observed in the same stretch of time. It does not show that the speech refers to the object in view.

The analyzer's report cannot supply this for audio at v1.1.0. The transcript is one string with no times, because Whisper's segment times are discarded. The audio-event stage returns no sound labels (checked 2026-11-27). Vision and audio are never aligned; they only meet if the text is passed to a language model.

Times are available if you call the libraries yourself: Whisper returns segment times, and for PANNs you choose the windows. The timeline below combines the analyzer's frames and detections for a 9 s test clip with the output of separate direct runs of Whisper and PANNs on its audio. The last two lanes are not something the analyzer exports.

Frames, detections, speech and sound tags on one time axis

On screen (clip construction)portraitcatcoffeeSampled framesHighest scoring label per frameSpeech segment (Whisper, direct)one segmentTop sound tag (PANNs, direct)Speech synthesizerSpeech02468seconds
What each lane holds at the selected time
laneholds
On screen (clip construction)portrait
Sampled framesa sampled frame
Highest scoring label per frameperson
Speech segment (Whisper, direct)one segment
Top sound tag (PANNs, direct)Speech synthesizer
Events, with the sampled frames inside each visual event
eventlanetimeSampled frames
portraitOn screen (clip construction)0 to 3 sframe at 0, 1, 2 s and 1 more
catOn screen (clip construction)3 to 6 sframe at 3, 4, 5 s and 1 more
coffeeOn screen (clip construction)6 to 9 sframe at 6, 7, 8 s
personHighest scoring label per frame0 s—
personHighest scoring label per frame1 s—
personHighest scoring label per frame2 s—
catHighest scoring label per frame3 s—
catHighest scoring label per frame4 s—
catHighest scoring label per frame5 s—
diningtableHighest scoring label per frame6 s—
diningtableHighest scoring label per frame7 s—
diningtableHighest scoring label per frame8 s—
one segmentSpeech segment (Whisper, direct)0 to 6 s—
Speech synthesizerTop sound tag (PANNs, direct)0 to 5 s—
SpeechTop sound tag (PANNs, direct)5 to 9 s—

Sampled frames: 9 frames in 9 s (1 per second); visual events without a sampled frame: 0 of 3.

At 0 s. On screen (clip construction): portrait. Sampled frames: a sampled frame. Highest scoring label per frame: person. Speech segment (Whisper, direct): one segment. Top sound tag (PANNs, direct): Speech synthesizer.

Select a time and compare how precise each source is: points for frames, a 6 s speech segment, audio windows of several seconds. Measured times and events, as recorded by the author: 9 s clip; frames, labels: analyzer v1.1.0 (dfine-s). Speech: openai-whisper 20250625 base. Sound: panns-inference 0.1.1 CNN14. Both run directly. The figure only displays and compares them. A frame shows a visual event when its time lies from the start to the end, both included.

The resolution differs by source. Whisper returned the whole narration as a single six second segment, so the evidence cannot say at which second the word "cat" was spoken relative to the cat appearing. The second sound window, from 5 s, is labelled speech although the voice stops within its first half second; Whisper's segment end of 6.0 s is itself only an estimate.

For loading, querying and checking these records in code, see working with video analysis JSON.

If your next step is to model relations between such observations as a graph, building vision graphs covers constructions for that. The analyzer itself builds no graph.

A summary is not coverage

A language model that summarizes a report receives only what the report holds, often less. It cannot recover an event that left no trace in the records, and a fluent paragraph hides where the gaps are. Keep observation and interpretation apart:

Observed (in the records) Inferred (not in the records)
a cat box in frames at 3.0, 4.0 and 5.0 s the cat was visible continuously from 3 s to 6 s
cup boxes in three frames there are three cups
no dog box in any sampled frame there is no dog in the video
the transcript contains a word someone in view said it
a caption mentions a flag a flag is relevant to the story

Some of these inferences are often reasonable. They are still inferences, and a report should say so.

Summarizing a video with timestamped evidence shows one way to make a local model cite the records behind each sentence, and where that check stops.

Hosted video models can sample too

Sending a file to a hosted model does not remove the question. Google's video understanding documentation for Gemini, as read on 2026-11-27, states that "for visual descriptions, the model samples the video at a rate of 1 frame per second" and warns that it "may miss details in videos with rapid motion or quick scene changes". It also documents a configurable frame rate and, for some models, a mode that chooses what to load as it goes. Other providers and later versions may differ, so ask any of them: which frames does the model receive, how is audio handled, and how are times assigned?

A model that reasons across the sampled frames can describe actions that a per-image detector cannot. It is still limited to what the samples contain.

Reviewing an analysis

Before relying on any result, record:

  1. the sampling strategy, its settings and the number of frames selected;
  2. how timestamps were computed, and whether the file has a constant frame rate;
  3. which models saw which frames, and which stages failed or produced nothing;
  4. the shortest event you care about, compared with the largest gap between samples.

Looking at the sampled times on a timeline makes the gaps visible. One way to do that interactively is Anastig Vision Lab, a separate, early-access browser workbench. In its on-device mode it samples frames from a video, runs a COCO detector and shows per-frame detection counts on a timeline, with a cap of 240 sampled frames per run. It does not read the analyzer's reports. Disclosure: the author of this article is also involved in building Anastig.

References