Skip to content

[feat] Add PyNvBatchAsyncStreamReader for 2D batched async stream dec…#20

Open
xupinjie wants to merge 3 commits into
NVIDIA:mainfrom
xupinjie:pinjie/async_stream_decode_2d
Open

[feat] Add PyNvBatchAsyncStreamReader for 2D batched async stream dec…#20
xupinjie wants to merge 3 commits into
NVIDIA:mainfrom
xupinjie:pinjie/async_stream_decode_2d

Conversation

@xupinjie
Copy link
Copy Markdown
Collaborator

@xupinjie xupinjie commented May 15, 2026

Description

Introduces a new async-only video decoder under accvlab.on_demand_video_decoder that decodes V videos × F frames per video in a single in-flight async submission, returning List[List[RGBFrame]] indexed [v][f]. Targeted at StreamPETR-like workloads consuming multi-sweep batches per training step.

Type of Change

Please select (at least one):

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation / examples / tutorials / demos
  • Supporting functionality change (fix or feature in documentation generation, helper scripts, ...)
  • Refactoring / internal change
  • Other (please describe):

Testing

Checklist for testing:

  • Tests added or updated if/as needed
  • Repository test runner executed: scripts/run_tests.sh

Optionally, add a brief description.

Documentation, Examples, Tutorials, Demos

Checklist for documentation:

  • User-facing documentation updated if/as needed (including API docs)
  • Examples / tutorials / demos updated or added (if relevant)
  • Limitations and constraints documented (if relevant)
  • Performance documented (if relevant)
  • Documentation building successful & checks outlined in the Documentation Checks section of the Contribution Guide are performed

Optionally, add a brief description.

Code Quality

Checklist for dependencies:

  • Dependencies updated in the relevant pyproject.toml if/as needed
  • Code formatted according to the Code Formatting Guide

Optionally, add a brief description.

Related Issues / Context

If applicable, link related issues, discussions etc.


DCO / Sign-Off

Please refer to the section on Signing Your Work & Developer Certificate of Origin (DCO)
in the Contribution Guide before submitting your contribution.

References

For additional details, please refer to the Contribution Guide.
The following guides are available (referenced in the Contribution Guide for further details):

Please also refer to the summary checklist in the Contribution Guide,
which is a guideline for what to consider when submitting your contribution and covers the same topics as the checklists above.

@xupinjie xupinjie requested a review from RmSchaffert May 15, 2026 09:42
@xupinjie xupinjie self-assigned this May 15, 2026
@xupinjie xupinjie marked this pull request as ready for review May 16, 2026 16:27
Copy link
Copy Markdown
Collaborator

@RmSchaffert RmSchaffert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
I added some inline comments in the code. Please have a look.

remains the right choice when you only need one frame per video per
iteration.

**Key Differences from 1D Async Stream Access**
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be good to mention that the file list remains the same (i.e. a flat list with one file name per camera) for both methods. Although this is already implied by the description above, I think it may help with understanding.


**File:** `packages/on_demand_video_decoder/samples/SampleBatchAsyncStreamAccess.py`

**When to Use**
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this improve performance or is it "just" a convenience feature? It may be good to add a short note on that as especially the third point in the list below seems to indicate that this is a convenience feature.

> views into the reader's internal aggregator pool. Submitting the next
> {py:meth}`~accvlab.on_demand_video_decoder.PyNvBatchAsyncStreamReader.Decode`
> reuses that memory. You **must** clone every frame you want to keep
> **before** the next ``Decode()`` call. Skipping the clone is silent data
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I would say "Skipping the clone [leads to]" instead of "[is]"

can be extracted (limited / MPEG range is assumed).

Returns:
PyNvBatchAsyncStreamReader instance.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider making PyNvBatchAsyncStreamReader a reference (link) to allow for easy navigation when reading the docs.

to a background C++ worker thread and returns the decoded frames as
``List[List[RGBFrame]]`` indexed ``[v][f]``. It is async-only (no sync
``Decode`` method) and 2D-only. The 1D ``PyNvSampleReader`` class is
unchanged and serves the 1-frame-per-video case.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove the "is unchanged" formulation, as this refers to a prior version instead of describing the current state.

Clear all underlying video readers. Waits for pending async task first.
)pbdoc")
.def(
"release_device_memory",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should release_device_memory and release_decoder be in camel case? The other methods are in upper camel case. However, I see that other decoders have some methods in snake case. Are these methods special?

# Stage detection: is Decode actually implemented?
# ---------------------------------------------------------------------------

def _probe_decode_implemented():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed? As the implementation is already available, it may be better to remove this to avoid unneeded complexity in the code.

.. literalinclude:: ../examples/demo.py
```

Inside Python docstrings, paths are relative to the file that includes the docstring (the autodoc directive's location), so absolute paths are acceptable there.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolute paths (w.r.t. the local file system) would still break.
Maybe something like:

For directives inside Python docstrings rendered by autodoc:
1. Find the docs file that renders the docstring, usually `packages/<pkg>/docs/api*.rst`.
2. Resolve directive paths from that docs file, not from the Python source file.
3. Prefer files under `packages/<pkg>/docs/`, e.g. `.. image:: images/foo.png`.
4. For package-root sibling dirs listed in `docu_referenced_dirs.txt`, use paths from `docs/`, e.g. `.. literalinclude:: ../example/foo.py`.
5. Never use machine-local absolute filesystem paths such as `/home/user/...`.


### Rule 9 — Edit source, not mirror

Source-of-truth lives at `packages/<pkg>/docs/`. Files under `docs/contained_package_docs_mirror/<pkg>/docs/` are symlinks regenerated by `mirror_referenced_dirs.py` at build time. Editing the mirror is at best a no-op and at worst destructive (overwritten on next build).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: In the best case, the edit would actually be done to the original file (as symlinks are used). Maybe say something like:

In the best case, this would work accidentally (due to symlink behavior), but in the worst case, ...

python SampleStreamAsyncAccess.py
```

#### 3.2.4 Sample: Batch Async Stream Access (2D)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be good to mention in the description that for each V, the same number of frames must be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants