AlgoMaster Logo

Exercise: Video Understanding and Generation

3 min readUpdated June 22, 2026
Listen to this chapter
Unlock Audio

Exercise 1: Summarize a Video from Sampled Frames

Understand a video by sampling a few frames, describing each with a vision model, and summarizing the descriptions into an account of what happens across the clip.

Models do not watch video directly; the standard approach is to sample frames at intervals and treat them as a sequence of images. Each frame gets a description, and a language model stitches those descriptions into a narrative. Sampling is the key decision: too few frames and you miss the action, too many and you waste tokens on near-identical images.

Requirements

  • Use a small set of frame image URLs that represent samples from a video, in order.
  • Describe each frame with a vision model.
  • Pass the ordered descriptions to a chat model and ask for a summary of what happens across the video.
  • Print each frame description and the final summary.
main.py
Loading...

Expected Output

Each frame is described, and the summary reads the descriptions as a sequence.

Solution

main.py
Loading...

Sampling reduces a video to a manageable sequence of images, and keeping the frames in order is what lets the summarizer describe change over time rather than a bag of unrelated pictures. The per-frame descriptions are the bridge: once the visual content is text, the summary step is ordinary text work. The number of frames you sample is the lever that trades cost against how much of the action you capture.

Exercise 2: Answer a Question About a Video

Once a video is captioned frame by frame, you can do more than summarize it: you can answer questions about it. Caption the sampled frames, then answer a specific question using those captions as context. This is video question-answering built on the same caption-then-reason pipeline.

Requirements

  • Caption each frame in order with a vision model.
  • Combine the ordered captions as context.
  • Answer a specific question about the video using only the captions, and print the answer.
main.py
Loading...

Expected Output

The captions establish that a cat appears in the first frame, and the answer reflects that.

Solution

main.py
Loading...

Question-answering reuses the frame captions as evidence, the same way RAG answers from retrieved chunks: the model reasons over the text descriptions rather than the pixels. Keeping the frames ordered lets it answer questions about sequence and change, not just presence. The captioning prompt sets the ceiling on what you can ask, since a detail no caption mentions is invisible to the answer step. It needs a vision-capable model and access to the frame URLs.