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
Coding & Algorithms
Software Engineer
Luma AI
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
Index math
Rounding
Frame rate conversion
Integer arithmetic
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements

Input: n source frames, src_fps, dst_fps (positive integers). Output frame k sits at time k/dstk/dst seconds; choose source frame whose time i/srci/src is nearest, ties rounded up. Keep duration: ou...

High-Level Design

Nearest source index is round(k⋅src/dst)round(k \cdot src / dst). 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) / (...


Submit Your Answer
Markdown supported

Related Questions