Cheat sheets

Video-Language Models and Long Video

Sample frames, budget tokens, encode time, ground events and index long video with timestamped answers.

  • Concepts and terms
  • Tasks and commands
  • Annotated code
  • Diagrams
  • Comparisons
  • Defaults and numbers
  • Troubleshooting
  • Questions and tips

Source

Scene index pipeline (capstone)#

keyframeaudiothree queriestop scenewindowclientVideo fileYouTube URL orlocal MP4processScenesegmentationTransNetV2 orPySceneDetectmodelVLM captioncaption + frameembeddingstoreMulti-vectorQdrantthree namedvectorsmodelASR passWhisper-v3-turbo,word timestampsclientQuestionnatural languageprocessRRF mergetop-k=5 scenesprocessTemporalgroundingrefine start, endin scenemodelVLM synthanswer +timestampskeyframeaudiothree queriestop scenewindowclientVideo fileYouTube URLor local MP4processScenesegmentationTransNetV2 orPySceneDetectmodelVLM captioncaption +frameembeddingstoreMulti-vectorQdrantthree namedvectorsmodelASR passWhisper-v3-turbo,wordtimestampsclientQuestionnaturallanguageprocessRRF mergetop-k=5scenesprocessTemporalgroundingrefine start,end in scenemodelVLM synthanswer +timestamps

From Lesson 19.12

Video VLM designs#

FactorVideo-LLaMAVideo-LLaVAQwen2.5-VL
Frames16-frame clips at 2 FPS8 framesDynamic FPS
CompressorVideo Q-former, 32 queriesMLPTMRoPE per token
Time position1D temporal RoPELearned temporal embeddingsAbsolute timestamp (t, h, w)
NoteAudio branch, ImageBindShared image+video encoderBest open 2025
Answer to "when""early in the clip"8-16 frame system"at 4.2 seconds"
WeaknessFixed clip lengthNo long videoNone stated

From Lesson 12.17, 12.17 code/main.py

Long video: four paths#

FactorBrute contextRing attentionToken compressionAgentic retrieval
ExampleGemini 1.5, Gemini 2.5 ProLWM, LongVILAVideo-XL, LongVAVideoAgent
MechanismAll tokens in one passChunks rotate across devicesOne summary token per clipLLM queries a clip tool
CostMillions of tokensLinear in contextSmall contextOnly relevant clips
WeaknessClosed, not open-sourceSpreads over many devicesMisses exact framesRetrieval quality
Pick for>1h general QA15-60 min15-60 min>1h specific query

From Lesson 12.18, 12.18 code/main.py

VideoAgent loop#

1LLMreads the question.2LLMcalls find_clips(keyword='<word>') for relevantclips.3Toolreturns matching clip timestamps.4VLMencodes 3 x 30s clips (~7290 tokens total).5LLMcomposes the answer or asks follow-up queries.

From Lesson 12.18, 12.18 code/main.py

Token math#

Budget
tokens(duration_s, fps, per_frame) is duration times FPS times tokens per frame.
Raw
1 minute at 30 FPS and 196 tokens per frame is 352k tokens.
3x3 pool
64 tokens per frame. 5 minutes at 1 FPS is 19,200 tokens.
384 native
~729 tokens per frame. 3x3 pooling gives 81.
30 min
1 FPS at 81 tokens is 145,800 tokens. 2 FPS is 291,600.
2 hours
1 FPS at 81 tokens is 583k tokens.
Retrieval
3 * 30 * 81 + 200 tokens for 3 clips. 99% cheaper.

From Lesson 12.17, Lesson 12.18, 12.18 code/main.py

Sample, ground, inflate#

uni = uniform_sample(duration, 8)step * (i + 0.5)
dyn = dynamic_sample(motion, fps_cap=4, total_budget=12)1 to fps_cap per second
result = evaluate_grounding(predictions, ground)hit when IoU >= tol_iou
result["recall"]hits over ground truth events
model = FramePool(num_classes=10, pretrained=False)ResNet-18 per frame, mean over T
c3d = inflate_2d_to_3d(c2d, time_kernel=3)repeat on time, divide by time_kernel
c21 = Conv2Plus1D(3, 16)spatial, BN, ReLU, temporal

From 12.17 code/main.py, 04.12 code/main.py

Video model families (vision)#

2D + pool
2D CNN per frame, average over time. Cannot model motion.
3D conv
kernels over (T, H, W). C3D, I3D, SlowFast.
I3D inflation
copy a 2D kernel along time. 3x3 becomes 3x3x3.
(2+1)D
2D spatial conv, then 1D temporal conv. Fewer parameters.
Joint attention
one attention over (t, h, w). Quadratic in T*H*W.
Divided attention
one attention over time, one over space, per block.
Factorised attention
time and space attention alternate across blocks.

From Lesson 04.12

Functions in code#

TaskCode
Uniform timestampsuniform_sample(duration, n)
Motion-aware timestampsdynamic_sample(motion, fps_cap=4, total_budget=32)
Score groundingevaluate_grounding(predictions, ground_truth, tol_iou=0.3)
Interval overlapiou(a_start, a_end, b_start, b_end)
Uniform frame indicessample_uniform(num_frames_total, T)
Random contiguous windowsample_dense(num_frames_total, T, rng=None)
Lift 2D conv to 3Dinflate_2d_to_3d(conv2d, time_kernel=3)
Search three vectorsmulti_vector_search(query, scenes, k=5)

From 12.17 code/main.py, 04.12 code/main.py, 19.12 code/main.py

Run the capstone#

CommandWhat it does
python main.pyIndex demo: RRF search, grounded window
npm run typecheckType checks the UI half
npm testJob state and store tests
npm startSelf-terminating demo
npm run serveHTTP server on :8123
GET /jobsJob summaries as JSON
GET /job/:idStage timeline, 404 when unknown
Stageschunk, embed, index, qa

From 19.12 code/main.py, 19.12 code/ts/README.md, 19.12 code/ts/src/server.ts, 19.12 code/ts/src/types.ts

Defaults#

SettingDefaultNote
fps_cap4Max samples per second
total_budget32Total dynamic samples
tol_iou0.3IoU for a grounding hit
time_kernel3Inflation time depth
RRF constant60Adds 1.0 / (60 + rank + 1)
k in search5Top scenes after fusion
Clip length T8Also 16, 32 or 64

From 12.17 code/main.py, Lesson 12.17, 04.12 code/main.py, Lesson 04.12, 19.12 code/main.py

Troubleshooting#

SymptomCauseFix
"open door" equals "close door"Temporal pooling is order-invariantUse 3D conv or a transformer
Near-chance on motion classesAppearance alone is insufficientTrain R(2+1)D, not FramePool
Inflated model breaks batch normActivation scale growsDivide by time_kernel
Joint attention runtime balloonsQuadratic in T*H*WUse divided attention
Uniform sampling misses the actionLoses motion peaksUse dynamic FPS with a max-frame cap
Answer says "early in the clip"No absolute time positionUse TMRoPE and JSON output
Context overflow on 2h video583k tokens at 1 FPSPool more or use VideoAgent
Miscounts "how many X"Counting hallucinationReport counting accuracy separately

From Lesson 04.12, Lesson 12.17, Lesson 12.18, Lesson 19.12

Questions#

What does TMRoPE add?
Absolute time per token. It handles uneven dynamic FPS spacing.
Which output format?
Structured JSON with time and event fields.
Which pooling?
3x3 bilinear for most tasks. 6x6 for agent workflows.
Which path for a 15-minute clip?
Open 72B with native context.
Which path for 2+ hours?
VideoAgent or hierarchical summaries.
78% clip, 82% video?
The model relies on test-time averaging.
Why three vectors per scene?
One pooled vector gives a retrieval regression.

From Lesson 12.17, Lesson 12.18, Lesson 04.12, Lesson 19.12

Benchmarks#

VideoMME
short, medium and long video. 2500+ samples.
TempCompass
"before" / "after" ordering questions.
EgoSchema
long-horizon first-person video.
Needle-in-a-haystack
hide a marker at a random point. Score Recall@k.

From Lesson 12.17, Lesson 12.18