Skip to content

Commit c340d60

Browse files
committed
Apply comments
1 parent 1e26576 commit c340d60

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

examples/file_like.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
do not reside locally, we will show how to only download the data segments that
1414
are needed to decode the frames you care about. We accomplish this capability
1515
with Python
16-
`file-like objects <https://docs.python.org/3/glossary.html#term-file-like-object>`_."""
16+
`file-like objects <https://docs.python.org/3/glossary.html#term-file-like-object>`_.
17+
Our example uses a video file, so we use the :class:`~torchcodec.decoders.VideoDecoder`
18+
class to decode it. But all of the lessons here also apply to audio files and the
19+
:class:`~torchcodec.decoders.AudioDecoder` class."""
1720

1821
# %%
1922
# First, a bit of boilerplate. We define two functions: one to download content
@@ -70,7 +73,7 @@ def bench(f, average_over=20, warmup=2):
7073
pre_downloaded_raw_video_bytes = get_url_content(nasa_url)
7174
decoder = VideoDecoder(pre_downloaded_raw_video_bytes)
7275

73-
print(f"Video size in MB: {len(pre_downloaded_raw_video_bytes) / 1024 / 1024}")
76+
print(f"Video size in MB: {len(pre_downloaded_raw_video_bytes) // 1024 // 1024}")
7477
print(decoder.metadata)
7578

7679
# %%
@@ -143,6 +146,9 @@ def direct_url_to_ffmpeg():
143146
# needed. Rather than implementing our own, we can use such objects from the
144147
# `fsspec <https://github.com/fsspec/filesystem_spec>`_ module that provides
145148
# `Filesystem interfaces for Python <https://filesystem-spec.readthedocs.io/en/latest/?badge=latest>`_.
149+
# Note that using these capabilities from the `fsspec` library also requires the
150+
# `aiohttp <https://docs.aiohttp.org/en/stable/>`_ module. You can install both with
151+
# `pip install fsspec aiohttp`.
146152

147153
import fsspec
148154

@@ -152,8 +158,8 @@ def stream_while_decode():
152158
# session; we need to indicate that we need to trust the environment
153159
# settings for proxy configuration. Depending on your environment, you may
154160
# not need this setting.
155-
with fsspec.open(nasa_url, client_kwargs={'trust_env': True}) as file:
156-
decoder = VideoDecoder(file, seek_mode="approximate")
161+
with fsspec.open(nasa_url, client_kwargs={'trust_env': True}) as file_like:
162+
decoder = VideoDecoder(file_like, seek_mode="approximate")
157163
return decoder[0]
158164

159165

0 commit comments

Comments
 (0)