Skip to content

Commit 8fbeafa

Browse files
committed
Say file-like instead of io types
1 parent a243ab1 commit 8fbeafa

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/torchcodec/decoders/_audio_decoder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ class AudioDecoder:
2626
Returned samples are float samples normalized in [-1, 1]
2727
2828
Args:
29-
source (str, ``Pathlib.path``,
30-
``io.RawIOBase``, ``io.BufferedReader``,
31-
bytes, or ``torch.Tensor``): The source of the audio:
29+
source (str, ``Pathlib.path``, bytes, ``torch.Tensor`` or file-like object): The source of the video:
3230
3331
- If ``str``: a local path or a URL to a video or audio file.
3432
- If ``Pathlib.path``: a path to a local video or audio file.
35-
- If ``io.RawIOBase`` or ``io.BufferedReader``: a file-like object that refers to a audio file.
3633
- If ``bytes`` object or ``torch.Tensor``: the raw encoded audio data.
34+
- If file-like object: we read video data from the object on demand. The object must
35+
expose the methods ``read(self, size: int) -> bytes`` and
36+
``seek(self, offset: int, whence: int) -> bytes``. Read more in TODO_FILE_LIKE_TUTORIAL.
3737
stream_index (int, optional): Specifies which stream in the file to decode samples from.
3838
Note that this index is absolute across all media types. If left unspecified, then
3939
the :term:`best stream` is used.

src/torchcodec/decoders/_decoder_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def create_decoder(
3535
return core.create_from_tensor(source, seek_mode)
3636
elif isinstance(source, io.TextIOBase):
3737
raise TypeError(
38-
"source is of type io.TextIOBase; did you forget to specify binary reading?"
38+
"source is for reading text, likely from open(..., 'r'). Try with 'rb' for binary reading?"
3939
)
4040
elif hasattr(source, "read") and hasattr(source, "seek"):
4141
# This check must be after checking for text-based reading. Also placing
@@ -46,5 +46,7 @@ def create_decoder(
4646

4747
raise TypeError(
4848
f"Unknown source type: {type(source)}. "
49-
"Supported types are str, Path, io.RawIOBase, io.BufferedReader, bytes and Tensor."
49+
"Supported types are str, Path, bytes, Tensor and file-like objects with "
50+
"read(self, size: int) -> bytes and "
51+
"seek(self, offset: int, whence: int) -> bytes methods."
5052
)

src/torchcodec/decoders/_video_decoder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class VideoDecoder:
2222
"""A single-stream video decoder.
2323
2424
Args:
25-
source (str, ``Pathlib.path``,
26-
``io.RawIOBase``, ``io.BufferedReader``,
27-
bytes, or ``torch.Tensor``): The source of the video:
25+
source (str, ``Pathlib.path``, bytes, ``torch.Tensor`` or file-like object): The source of the video:
2826
2927
- If ``str``: a local path or a URL to a video file.
3028
- If ``Pathlib.path``: a path to a local video file.
31-
- If ``io.RawIOBase`` or ``io.BufferedReader``: a file-like object that refers to a video file.
3229
- If ``bytes`` object or ``torch.Tensor``: the raw encoded video data.
30+
- If file-like object: we read video data from the object on demand. The object must
31+
expose the methods ``read(self, size: int) -> bytes`` and
32+
``seek(self, offset: int, whence: int) -> bytes``. Read more in TODO_FILE_LIKE_TUTORIAL.
3333
stream_index (int, optional): Specifies which stream in the video to decode frames from.
3434
Note that this index is absolute across all media types. If left unspecified, then
3535
the :term:`best stream` is used.

0 commit comments

Comments
 (0)