Skip to content

[videoAPI] fast seek implementation #3014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bjuncek opened this issue Nov 17, 2020 · 1 comment
Closed

[videoAPI] fast seek implementation #3014

bjuncek opened this issue Nov 17, 2020 · 1 comment

Comments

@bjuncek
Copy link
Contributor

bjuncek commented Nov 17, 2020

🚀 Feature

Seek that seeks to the closest keyframe before requested timestamp

Motivation

At the moment, seek function is restricted to a precise seek which under the hood finds the closest keyframe, and decodes frames until we reach our targeted frame. This is a convenient, however potentially slower operation. We want users to be able to decide if they want to seek to keyframes only (for the fastest possible version), we should allow it for them.

Pitch

Imagine we have a video with keyframes at 0s and 8.3s. Then the precise seek (current implementation) works as follows:

video.seek(2)
data = next(video)
print(data['pts'])
>> 2.002

video.seek(5)
data = next(video)
print(data['pts'])
>> 5.005

video.seek(9)
data = next(video)
print(data['pts'])
>> 9.009

And the imprecise seek (keyframes only):

video.seek(2, keyframes_only=True)
data = next(video)
print(data['pts'])
>> 0.0

video.seek(5, keyframes_only=True)
data = next(video)
print(data['pts'])
>> 0.0

video.seek(9, keyframes_only=True)
data = next(video)
print(data['pts'])
>> 8.341667

Additional context

This is a function provided in pyav already, so I think it would be useful to have it as an option.

Note:

This requires changes in the decoder C++ API which is IIUC used internally in FB; before accepting the PR, @fmassa should probably look into importing it and testing it internally. The default values and operations are kept the same, but nevertheless, there could be regressions not caught by our current tests.

cc @bjuncek

@bjuncek bjuncek self-assigned this Nov 17, 2020
@vfdev-5 vfdev-5 changed the title [vidnoAPI] fast seek implementation [videoAPI] fast seek implementation Dec 18, 2020
@bjuncek
Copy link
Contributor Author

bjuncek commented Mar 17, 2022

closed via #3179

@bjuncek bjuncek closed this as completed Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant