pytorch / torchcodec

PyTorch video decoding
BSD 3-Clause "New" or "Revised" License
77 stars 9 forks source link

Ensure we don't read invalid memory when seeking to pts before the first frame #331

Closed ahmadsharif1 closed 2 days ago

ahmadsharif1 commented 2 days ago

This PR does:

  1. Ensures we don't read keyFrames[-1] when trying to seek before the first keyFrame. Note that our function returns the last keyframe whose pts is <= to the desired pts. And it returns -1 if no such keyframe is found.
  2. We also use a single function to convert seconds to pts. Here we do a call to std::round() to ensure that we go back to int64 as faithfully as possible. Previously we were truncating and that could lead to off-by-one errors.

This fixes #307 (in particular, (1) fixes that)

I added a test for (1) but adding a test for (2) requires a lot of precise video editing that I haven't done.