-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e288474
commit f2c0ff8
Showing
8 changed files
with
83 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
_target_: rbyte.io.frame.VideoFrameReader | ||
path: ??? | ||
threads: !!null | ||
resize_shorter_side: !!null | ||
with_fallback: !!null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ maintainers = [{ name = "Evgenii Gorchakov", email = "[email protected]" }] | |
dependencies = [ | ||
"tensordict @ git+https://github.com/pytorch/tensordict.git@85b6b81", | ||
"torch>=2.4.1", | ||
"polars>=1.8.0", | ||
"polars>=1.8.2", | ||
"pydantic>=2.9.2", | ||
"more-itertools>=10.5.0", | ||
"hydra-core>=1.3.2", | ||
|
@@ -44,6 +44,7 @@ mcap = [ | |
] | ||
yaak = ["protobuf", "ptars>=0.0.2rc2"] | ||
jpeg = ["simplejpeg>=1.7.6"] | ||
video = ["video-reader-rs>=0.1.4"] | ||
|
||
[project.scripts] | ||
rbyte-build-table = 'rbyte.scripts.build_table:main' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
from .directory import DirectoryFrameReader | ||
|
||
__all__ = ["DirectoryFrameReader"] | ||
|
||
try: | ||
from .video import VideoFrameReader | ||
except ImportError: | ||
pass | ||
else: | ||
__all__ += ["VideoFrameReader"] | ||
|
||
try: | ||
from .mcap import McapFrameReader | ||
except ImportError: | ||
pass | ||
else: | ||
__all__ += ["McapFrameReader"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .reader import VideoFrameReader | ||
|
||
__all__ = ["VideoFrameReader"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from collections.abc import Callable, Iterable, Sequence | ||
from functools import partial | ||
from os import PathLike | ||
from pathlib import Path | ||
from typing import override | ||
|
||
import torch | ||
import video_reader as vr | ||
from jaxtyping import UInt8 | ||
from pydantic import NonNegativeInt, validate_call | ||
from torch import Tensor | ||
|
||
from rbyte.io.frame.base import FrameReader | ||
|
||
|
||
class VideoFrameReader(FrameReader): | ||
@validate_call | ||
def __init__( | ||
self, | ||
path: PathLike[str], | ||
threads: NonNegativeInt | None = None, | ||
resize_shorter_side: NonNegativeInt | None = None, | ||
with_fallback: bool | None = None, # noqa: FBT001 | ||
) -> None: | ||
super().__init__() | ||
self._path = Path(path).resolve().as_posix() | ||
|
||
self._get_batch: Callable[[str, Iterable[int]], UInt8[Tensor, "b h w c"]] = ( | ||
partial( | ||
vr.get_batch, # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue] | ||
threads=threads, | ||
resize_shorter_side=resize_shorter_side, | ||
with_fallback=with_fallback, | ||
) | ||
) | ||
|
||
@override | ||
def read(self, indexes: Iterable[int]) -> UInt8[Tensor, "b h w c"]: | ||
batch = self._get_batch(self._path, indexes) | ||
|
||
return torch.from_numpy(batch) # pyright: ignore[reportUnknownMemberType] | ||
|
||
@override | ||
def get_available_indexes(self) -> Sequence[int]: | ||
num_frames, *_ = vr.get_shape(self._path) # pyright: ignore[reportAttributeAccessIssue, reportUnknownVariableType, reportUnknownMemberType] | ||
|
||
return range(num_frames) # pyright: ignore[reportUnknownArgumentType] |