diff --git a/examples/basic_example.py b/examples/basic_example.py new file mode 100644 index 00000000..29372890 --- /dev/null +++ b/examples/basic_example.py @@ -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)= 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=}") diff --git a/examples/basic_example_remove_me.py b/examples/basic_example_remove_me.py deleted file mode 100644 index e01bc496..00000000 --- a/examples/basic_example_remove_me.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -============= -Basic Example -============= - -Remove this! -""" - -# %% -print("This is a cell that gets executerd") -# %% -print("And another cell.") - -# %% -# We can write rst cells too! -# --------------------------- -# -# As if we're writing normal docs/docstrings. Let's reference the -# :class:`~torchcodec.decoders.SimpleVideoDecoder` class. Click on this and it -# should bring you to its docstring!! In the docstring, you should see a -# backreference to this example as well! -# -# And of course we can write normal code - -# %% -from torchcodec.decoders import SimpleVideoDecoder - -try: - SimpleVideoDecoder("bad_path") -except ValueError as e: - print(f"Ooops:\n {e}") - -# %% -print("All good!")