Skip to content
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

rename manual_seek to iterative_seek #1481

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions supervision/utils/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):


def _validate_and_setup_video(
source_path: str, start: int, end: Optional[int], manual_seek: bool = False
source_path: str, start: int, end: Optional[int], iterative_seek: bool = False
):
video = cv2.VideoCapture(source_path)
if not video.isOpened():
Expand All @@ -128,7 +128,7 @@ def _validate_and_setup_video(
start = max(start, 0)
end = min(end, total_frames) if end is not None else total_frames

if manual_seek:
if iterative_seek:
while start > 0:
success = video.grab()
if not success:
Expand All @@ -145,7 +145,7 @@ def get_video_frames_generator(
stride: int = 1,
start: int = 0,
end: Optional[int] = None,
manual_seek: bool = False,
iterative_seek: bool = False,
) -> Generator[np.ndarray, None, None]:
"""
Get a generator that yields the frames of the video.
Expand All @@ -158,7 +158,7 @@ def get_video_frames_generator(
video should generate frames
end (Optional[int]): Indicates the ending position at which video
should stop generating frames. If None, video will be read to the end.
manual_seek (bool): If True, the generator will manually seek to the
iterative_seek (bool): If True, the generator will seek to the
`start` frame by grabbing each frame, which is much slower. This is a
workaround for videos that don't open at all when you set the `start` value.

Expand All @@ -174,7 +174,9 @@ def get_video_frames_generator(
...
```
"""
video, start, end = _validate_and_setup_video(source_path, start, end, manual_seek)
video, start, end = _validate_and_setup_video(
source_path, start, end, iterative_seek
)
frame_position = start
while True:
success, frame = video.read()
Expand Down