Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions examples/decoding/approximate_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
# Performance: ``VideoDecoder`` creation
# --------------------------------------
#
# In terms of performance, the ``seek_mode`` parameter ultimately affects the
# In terms of performance, the ``seek_mode`` parameter mainly affects the
# **creation** of a :class:`~torchcodec.decoders.VideoDecoder` object. The
# longer the video, the higher the performance gain.

Expand Down Expand Up @@ -104,7 +104,7 @@ def bench(f, average_over=50, warmup=2, **f_kwargs):
# ---------------------------------------------
#
# Strictly speaking the ``seek_mode`` parameter only affects the performance of
# the :class:`~torchcodec.decoders.VideoDecoder` creation. It does not have a
# the :class:`~torchcodec.decoders.VideoDecoder` creation. It usually does not have a
# direct effect on the performance of frame decoding or sampling. **However**,
# because frame decoding and sampling patterns typically involve the creation of
# the :class:`~torchcodec.decoders.VideoDecoder` (one per video), ``seek_mode``
Expand Down Expand Up @@ -168,20 +168,21 @@ def sample_clips(seek_mode):
# duration), and also builds an internal index of frames and key-frames. This
# internal index is potentially more accurate than the one in the file's
# headers, which leads to more accurate seeking behavior.
# Without the scan, TorchCodec relies only on the metadata contained in the
# file, which may not always be as accurate.
# Without the scan (in approximate mode), TorchCodec relies only on the metadata
# contained in the file, which may not always be as accurate. In some rare
# cases, relying on this less accurate data may also lead to slower frame
# decoding, because it can involve unnecessary seeks.
#
# Which mode should I use?
# ------------------------
#
# The general rule of thumb is as follows:
#
# - If you really care about exactness of frame seeking, use "exact".
# - If you can sacrifice exactness of seeking for speed, which is usually the
# case when doing clip sampling, use "approximate".
# - If your videos don't have variable framerate and their metadata is correct,
# then "approximate" mode is a net win: it will be just as accurate as the
# "exact" mode while still being significantly faster.
# - If your videos are short (less then a few minutes) then "exact" will usually
# be preferable, as the scan's fixed cost will be negligible.
# - For long videos, if you can sacrifice exactness of seeking for speed, which
# is usually the case when doing clip sampling, consider using "approximate".

# %%
shutil.rmtree(temp_dir)
Expand Down
Loading