Skip to content

Commit 0595e3c

Browse files
scottsfacebook-github-bot
authored andcommitted
Update example to add get_frames_displayed_at() (#152)
Summary: Adds example usage of `get_frames_displayed_at()`. Incorporate it in such a way that the index-based and time-based examples parallel each other. Pull Request resolved: #152 Reviewed By: ahmadsharif1 Differential Revision: D60775439 Pulled By: scotts fbshipit-source-id: 69385771db1d83717a1f1acbf31ad50b5972f4eb
1 parent 16a4138 commit 0595e3c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

examples/basic_example.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,26 @@ def plot(frames: torch.Tensor, title : Optional[str] = None):
151151
#
152152
# So far, we have retrieved frames based on their index. We can also retrieve
153153
# frames based on *when* they are displayed with
154-
# :meth:`~torchcodec.decoders.SimpleVideoDecoder.get_frame_displayed_at`, which
155-
# also returns :class:`~torchcodec.decoders.Frame`.
154+
# :meth:`~torchcodec.decoders.SimpleVideoDecoder.get_frame_displayed_at` and
155+
# :meth:`~torchcodec.decoders.SimpleVideoDecoder.get_frames_displayed_at`, which
156+
# also returns :class:`~torchcodec.decoders.Frame` and :class:`~torchcodec.decoders.FrameBatch`
157+
# respectively.
156158

157159
frame_at_2_seconds = decoder.get_frame_displayed_at(seconds=2)
158160
print(f"{type(frame_at_2_seconds) = }")
159161
print(frame_at_2_seconds)
162+
163+
# %%
164+
first_two_seconds = decoder.get_frames_displayed_at(
165+
start_seconds=0,
166+
stop_seconds=2,
167+
)
168+
print(f"{type(first_two_seconds) = }")
169+
print(first_two_seconds)
170+
171+
# %%
160172
plot(frame_at_2_seconds.data, "Frame displayed at 2 seconds")
173+
plot(first_two_seconds.data, "Frames displayed during [0, 2) seconds")
161174

162175
# %%
163176
# Using a CUDA GPU to accelerate decoding

0 commit comments

Comments
 (0)