Metadata-Version: 2.4
Name: pixtreme-transport-sequence
Version: 0.6.0
Summary: Image sequence module for pixtreme.transport
License-Expression: MIT AND BSD-3-Clause
License-File: licenses/nanobind.txt
License-File: licenses/robin_map.txt
License-File: licenses/third-party.json
Project-URL: Homepage, https://github.com/sync-dev-org/pixtreme-transport-sequence
Project-URL: Repository, https://github.com/sync-dev-org/pixtreme-transport-sequence
Project-URL: Releases, https://github.com/sync-dev-org/pixtreme-transport-sequence/releases
Requires-Python: >=3.12
Requires-Dist: pixtreme>=2.35.0
Requires-Dist: pixtreme-transport>=0.61.1
Description-Content-Type: text/markdown

# pixtreme-transport-sequence

`pixtreme.transport.sequence` reads and writes numbered image sequences through
pixtreme's format-specific Readers and Writers. Its `SequenceEntrance` and
`SequenceExit` factories create pixtreme.transport sessions with the module name
`sequence`, using buffers owned by the caller. Input preserves the source colour
and alpha; output performs only image conversions explicitly allowed by the
caller through pixtreme.

## Installation and requirements

Install from PyPI:

```sh
python -m pip install pixtreme-transport-sequence
```

The release platforms are Linux x86_64 (glibc 2.28 or later) and native Windows
x86_64. Install a wheel for your platform from the selected release; a platform
is available only when that release provides its wheel. The supported Python
versions are standard CPython 3.12 and 3.13; wheels use the CPython 3.12 stable
ABI. Image I/O uses an NVIDIA GPU and requires the CUDA-compatible driver
specified by the installed [pixtreme](https://pypi.org/project/pixtreme/) release.

The only direct runtime dependencies are `pixtreme>=2.35.0` and
`pixtreme-transport>=0.61.1`. Python installation resolves these packages and
their own dependencies. Image formats are those supported by the installed
pixtreme Readers and Writers, selected by the filename extension.

## Python sessions

Create input and output sessions through `sequence`:

```python
from fractions import Fraction

from pixtreme.transport import sequence
from pixtreme.transport.session import ExitSettings, FrameBuffer, Pacing

device = 0  # Ordinal after CUDA_VISIBLE_DEVICES filtering.
input_buffer = FrameBuffer(2, mode="blocking")
source = sequence.SequenceEntrance(
    device,
    input_buffer,
    {
        "path": "input/frame_%04d.exr",
        "sequence.frame_rate": "24000/1001",
        "sequence.start_frame": "1",
    },
)

output_buffer = FrameBuffer(2, mode="blocking")
settings = ExitSettings(Fraction(1001, 24000))  # Frame period, in seconds.
settings.pacing = Pacing.NONE
settings.audio.enabled = False
target = sequence.SequenceExit(
    device,
    output_buffer,
    settings,
    {"path": "output/frame_%04d.exr", "sequence.start_frame": "1"},
)
```

Creation returns unopened sessions. Call `source.open()`, read with
`source.next()` until it returns `None`, and close the source in a `finally`
block. Each returned item's `frame` contains the image and timing. To write,
put the processed transport frames into `output_buffer`, open the target, close
the buffer after the last frame, and call `target.join()` to wait for all writes.
Close the target in a `finally` block. Run the producer and consumer concurrently
when filling a blocking buffer beyond its capacity. Create the output directory
before opening the target.

Input reads in display order as quickly as its blocking buffer accepts images.
It does not pace reads by the OS clock or attach receipt timestamps. For a file
pipeline, `Pacing.NONE` and FIFO selection write every accepted image once and
wait while the output buffer is empty and open. Closing and draining the buffer
finishes output. `Pacing.CORE_CLOCK` with FIFO selection is also accepted; it
writes the images and repeats supplied by the core at its output cadence.

### Sequence options

Options are strings, supplied as a mapping or an iterable of name/value pairs.

| Option | Input | Output |
|---|---|---|
| `path` | Required image filename pattern | Required image filename pattern |
| `sequence.frame_rate` | Required positive rational, such as `24000/1001` | Not accepted; use the core output frame period |
| `sequence.start_frame` | Optional decimal integer; otherwise find the first existing file among numbers 0–4 | Optional decimal integer; default `1` |

A path must contain exactly one printf-style `%0Nd` number field, with `N >= 1`:
`frame_%04d.exr` produces names such as `frame_0001.exr`. Use `%%` for a literal
percent sign. Glob patterns, `####` and explicit filename lists are not supported.

Input advances through consecutive numbers and ends at the first missing file.
A missing first image or an existing unreadable or undecodable image is an
error. Output numbers each received image consecutively from its start number.
Sequence input supplies images without audio, motion vectors or residuals;
output rejects enabled audio before writing an image. Unknown, duplicate,
missing or inapplicable settings fail with the setting name and reason.

### Player operations

An open input accepts absolute file-number seeks, inclusive playback ranges,
repeat counts, and media start, finish and replacement through the core's
`OperationRequest`. Configure `hold_at_end=True` before opening a source to
keep the session available for operations after media or range end. Without
that policy, input returns normal EOF and no longer accepts operations.

```python
from pixtreme.transport.session import OperationAdmission, OperationKind, OperationRequest

source.configure_operations(hold_at_end=True)  # Before source.open().
source.open()
submission = source.submit_operation(OperationRequest(OperationKind.SEEK, position=42))
if submission.admission == OperationAdmission.ACCEPTED:
    result = submission.result
    result.wait()  # Application; publication is a separate result stage.
    print(result.snapshot.applied_position)
```

Keep consuming input concurrently: pictures already in the caller's buffer
remain there. A seek's new picture has the exact requested file number and a
new numbered stream scope. The core marks its discontinuity, including a switch
whose new file numbers happen to continue the preceding sequence. Relative
one-frame steps use absolute numbers computed by the caller from its last
selected picture.

Use `OperationRequest(OperationKind.RANGE, first=10, last=19, repeat_count=2)`
for two passes including both endpoints. A count of `1` disables repetition;
`0` repeats until another operation or stop. A RANGE without endpoints removes
the playback range. Omitting its repeat count keeps the previous count and
restarts pass counting. When the next position falls outside a new range,
playback moves to its first file. A seek may select any file in the medium,
even outside the playback range; range completion occurs only after its last
file is emitted. The media range ends at the first missing consecutive file,
so files beyond a gap cannot be seek targets or range endpoints.
At an operable end, a range containing the last published picture keeps the
input waiting, even when its repeat count changes. Its applied position is
absent; use SEEK to resume. A range excluding that picture resumes at its first
file.

To switch input, send START_MEDIA or REPLACE_MEDIA with `media` set to the new
filename pattern and `options={"sequence.frame_rate": "24/1"}`. Supply the
optional `start_number` as a typed integer. Omission searches numbers 0–4.
Optional `position`, `first`/`last` and `repeat_count` apply atomically. Omitted
values use the new medium's first file (or its range's first file when a range
is supplied), the whole medium and no repetition. The previous medium's values
are not inherited. `sequence.start_frame` is a creation option and is rejected
in operation options. Invalid settings or missing initial files leave the old
medium usable.

An open output accepts START_MEDIA, REPLACE_MEDIA and FINISH_MEDIA. A switch
finishes earlier accepted writes before using the new pattern and its
`start_number` (default `1`). Seek and range operations are unsupported for
output. Result stages distinguish old-media completion, new-media preparation
and the first new write; `applied_position` is the new output's first number.
FINISH_MEDIA has no applied position. Applied positions remain fixed after
later operations and session close. Inspect `media_state` for the module's
latest media position, bounds and pass count; an unverified last number is
absent. Continue to close every session in a `finally` block.

## C and C++ SDK

Download the SDK archive for your platform and version, together with
`SHA256SUMS`, from the
[GitHub Releases](https://github.com/sync-dev-org/pixtreme-transport-sequence/releases).
Verify the archive's SHA256 before extracting it. The SDK provides the same
module library as the wheel, public headers, CMake package files and licenses.
Obtain compatible shared SDKs for
[pixtreme](https://github.com/sync-dev-org/pixtreme/releases) and
[pixtreme-transport](https://github.com/sync-dev-org/pixtreme-transport/releases)
separately; their libraries are supplied by those distributions.

Point CMake's `pixtreme_DIR`, `pixtreme_transport_DIR` and
`pixtreme_transport_sequence_DIR` to the extracted SDKs' `pixtreme/core/cmake`,
`pixtreme/transport/cmake` and `pixtreme/transport/sequence/cmake` directories,
respectively. C and C++ consumers can link the module through its imported
CMake target:

```cmake
find_package(pixtreme_transport_sequence CONFIG REQUIRED)
target_link_libraries(application PRIVATE pixtreme::transport_sequence)
```

C++ consumers use C++20. For creation by name, install the SDK trees under one
common prefix so the core can locate `pixtreme/transport/sequence/lib/` on Linux or
`pixtreme/transport/sequence/bin/` on Windows. Configure the platform's shared
library search paths for the dependencies and keep one copy of each shared
library per process.

Use `pixtreme_transport_module_create_entrance` and
`pixtreme_transport_module_create_exit` from `<pixtreme/transport/c/module.h>`
in C, or `pixtreme::transport::module::create_entrance` and `create_exit` from
`<pixtreme/transport/module.h>` in C++, passing the module name `sequence`.
Supply the device, caller-owned blocking buffer, output settings where needed,
and the same sequence options shown above. Check the core ABI before using
its operations, open each returned session to begin I/O, and close sessions
before releasing their owned handles.

The same typed media requests are defined in
`<pixtreme/transport/c/operation.h>` and exposed to C++ by
`<pixtreme/transport/session/operation.h>`. Submit them with the core entrance
or exit operation functions; the module factories and caller buffers stay the
same throughout media changes.

## License and third-party notices

The sequence module is licensed under the
[MIT License](https://github.com/sync-dev-org/pixtreme-transport-sequence/blob/main/LICENSE).
The Python binding incorporates nanobind (BSD-3-Clause) and robin-map (MIT).
Their copyright notices and license texts are in `nanobind.txt` and
`robin_map.txt`; `third-party.json` records their versions, source checksums and
build descriptions. These files are included in the wheel's license directory;
the `License-File` fields in its metadata give the relative paths. The SDK
includes the module license and the provenance record in its license materials.
It supplies the native module without the Python binding or its embedded
third-party implementations.
The separately installed pixtreme and pixtreme-transport dependencies carry
their own licenses and notices.
