Improve code to retrieve frame at a specific time