1313do not reside locally, we will show how to only download the data segments that
1414are needed to decode the frames you care about. We accomplish this capability
1515with 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):
7073pre_downloaded_raw_video_bytes = get_url_content (nasa_url )
7174decoder = 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 } " )
7477print (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
147153import 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