Resample Generated Video Frames To A New Frame Rate
Last updated: November 29, 2026
Quick Overview
A generated clip has n frames at src_fps and must be delivered at dst_fps with the same duration. Return the list of source frame indices to use for each output frame, picking the nearest source frame in time.
Luma AI
November 29, 20260
0
0 solved
A generated clip has n frames at src_fps and must be delivered at dst_fps with the same duration. Return the list of source frame indices to use for each output frame, picking the nearest source frame in time.
Video models often generate at a native frame rate (for example 24 fps) while exports and the API may need 30 or 60 fps, so retiming is a real pipeline step at a video-generation company. The interviewer checks clean index math, integer-only rounding and boundary handling rather than any clever algorithm.
What the Interviewer Expects
- State how many output frames fit the clip and why
- Map each output time to the nearest source frame with a defined tie rule
- Avoid floating-point drift by using integer arithmetic
- Clamp to the last valid source index
- Handle zero or invalid inputs
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you blend two neighbouring frames instead of picking the nearest one?
- How does this change if the source has variable frame timestamps?
- What artifacts does nearest-frame retiming cause at 24 to 30 fps (judder) and how would you hide them?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: n source frames, src_fps, dst_fps (positive integers). Output frame k sits at time seconds; choose source frame whose time is nearest, ties rounded up. Keep duration: ou...
High-Level Design
Nearest source index is . Doing this with floats over a long clip can drift and makes ties platform dependent, so compute it with integers: $\lfloor (2 k \cdot src + dst) / (...