-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[torchcodec] Add a simple example showing how to decode the first fra…
…me of a video (#51) Summary: Add a basic example of how to decode a frame from a video. Pull Request resolved: #51 Differential Revision: D59022932
- Loading branch information
1 parent
0de0c5e
commit 735ac7a
Showing
2 changed files
with
28 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
================================================== | ||
Basic Example to use TorchCodec to decode a video. | ||
================================================== | ||
""" | ||
|
||
# A simple example showing how to decode the first few frames of a video. | ||
# using the :class:`~torchcodec.decoders.SimpleVideoDecoder` class. | ||
# %% | ||
import inspect | ||
import os | ||
|
||
from torchcodec.decoders import SimpleVideoDecoder | ||
|
||
my_path = os.path.abspath(inspect.getfile(inspect.currentframe())) | ||
video_file_path = os.path.dirname(my_path) + "/../test/resources/nasa_13013.mp4" | ||
simple_decoder = SimpleVideoDecoder(video_file_path) | ||
num_frames = len(simple_decoder) | ||
# Should print: | ||
# video_file_path=nasa_13013.mp4 has 390 frames | ||
print(f"{video_file_path=} has {num_frames=} frames") | ||
first_frame = simple_decoder[0] | ||
# Should print: | ||
# type(first_frame)=<class 'torch.Tensor'> first_frame.shape=torch.Size([270, 480, 3]) | ||
print(f"{type(first_frame)=} {first_frame.shape=}") | ||
|
||
last_frame = simple_decoder[num_frames - 1] | ||
print(f"{last_frame.shape=}") |
This file was deleted.
Oops, something went wrong.