It seems, that I require the same functionality: list of frames is stored in memory and when user requests frame number N, I need the first keyframe, left to requested. They are stored in ets ordered set table (it becomes rather large), so I take all keyframes, left to requested and select first from them. Very, very non-optimal =(