Video and vision parameter reference
Inspect constructor defaults, frame lifetime, preprocessing variables, read outcomes and supplied box postprocessing contracts.
ImplementedAner 0.1.0 or newerThese signatures describe the native video and vision interfaces. Read Aner Video and Aner Vision for complete workflows. Defaulted parameters can be omitted by name. Module and receiver forms share the same checked contracts; for example video.read_into(source, frame) is source.read_into(frame).
Resource types
| Type | Ownership and mutation |
|---|---|
VideoSource | Shared native session; aliases share queue, counters and close |
VideoFrameSlot | Reusable mutable RGB8 CPU storage; aliases share updates |
VideoFrame | Immutable copied snapshot, charged to its source snapshot budget |
VideoWriter | Shared recording session with explicit finalization |
VisionPlan | Immutable preprocessing recipe |
VisionInput | Reusable current NCHW tensor and original frame mapping |
DetectionSet | Reusable bounded box results retaining frame identity |
Parameter limits and meanings
| Parameter | Contract |
|---|---|
width, height on video sources | Positive dimensions, at most 32768 each; packed RGB output must also fit its per frame budget |
frames | Nonnegative synthetic frame count; zero runs until stopped |
fps | Synthetic/recording: finite positive rate up to 1000. Camera: zero omits the rate preference; otherwise the same bound applies |
realtime | Pace synthetic acquisition and permit bounded latest frame delivery |
queue_frames | Integer 1..256; limits pending frames |
memory_mb | Source queues: integer 1..4096; frame slots: 1..1024. Units are MiB (1048576 bytes), despite the short argument name |
timeout_ms | Caller wait: integer 0..3600000 (zero polls). Backend I/O deadline: 1..3600000; worker operation continues after a caller timeout |
device | OS native capture locator; default selects the adapter default |
path | Local input path, or a new .mkv destination for recording |
url | Explicit supported endpoint; userinfo/fragments and recognized credential like query names are rejected. Bounded ordinary selectors are accepted |
ca_file | Empty for system trust, or a trusted CA bundle path; hostname/peer verification stays enabled |
authorization | Opaque SecretRef resolving a raw bearer token; snapshot only and HTTPS only. The adapter constructs the header |
x, y, channel | Zero based pixel indexes; channel 0..2 means R,G,B |
| vision output dimensions | Each 1..4096; at most 16777216 Float32 elements across all three channels |
resize | letterbox, stretch or crop |
filter | nearest or bilinear |
scale | Finite positive channel multiplier; applied before mean/std |
pad | Finite RGB8 domain value in [0,255] |
mean_r/g/b | Finite channel means after scale |
std_r/g/b | Finite positive channel divisors |
max_detections | Integer 1..4096; retained output capacity |
score_threshold, iou_threshold | Finite values in [0,1] |
max_candidates | Integer 1..65536; admitted Nx6 row bound |
index | Zero based detection index below current result count |
URLs are limited to 4096 bytes, 64 query parameters, 128 decoded bytes per parameter name and 1024 bytes per query pair. Credential name filtering is conservative and cannot classify arbitrary values as secrets. Query selectors are intended for nonsecret camera configuration.
Queue, snapshot and slot budgets are distinct. Decoder working state and tensors are additional allocations; these limits are not a process memory quota. General native tensor budgets still apply to downstream computation.
Constructors and module functions
The tables list complete native forms, including overloads. A receiver method omits the first explicit argument. value represents the typed receiver shown in that row.
Video functions
| Signature | Result | Contract |
|---|---|---|
video.available() | Bool | Report whether this build includes the installed FFmpeg video backend. Synthetic sources remain available without it. |
video.camera_backend() | String | Return the compiled OS camera adapter name without opening a camera. |
video.devices() | String | Return bounded device enumeration JSON; unsupported enumeration is explicit. |
video.frame_slot(memory_mb: Int64 = 64) | VideoFrameSlot | Create a reusable native RGB8 frame slot; aliases share updates, with an explicit MiB payload limit. |
video.synthetic(width: Int64 = 320, height: Int64 = 240, frames: Int64 = 30, fps: Float64 = 30.0, realtime: Bool = false, queue_frames: Int64 = 2, memory_mb: Int64 = 128) | VideoSource | Create a deterministic RGB8 source. Zero frames is unbounded. Offline sources preserve order; realtime sources use bounded latest frame delivery. |
video.file(path: String, queue_frames: Int64 = 2, memory_mb: Int64 = 128) | VideoSource | Decode a local recording in order using bounded buffering. Requires the optional FFmpeg backend. |
video.camera(device: String = "default", width: Int64 = 640, height: Int64 = 480, fps: Float64 = 30.0, queue_frames: Int64 = 2, memory_mb: Int64 = 128) | VideoSource | Open an OS camera locator with bounded latest frame delivery. Requested modes must be supported; inspect received frame geometry. |
video.stream(url: String, queue_frames: Int64 = 2, memory_mb: Int64 = 128, timeout_ms: Int64 = 3000) | VideoSource | Open an allowed remote media URL. Credentials embedded in URLs are rejected; timeout is an IO deadline, and read outcomes remain distinct. |
video.read_into(source: VideoSource, frame: VideoFrameSlot, timeout_ms: Int64 = 1000) | String | Replace the reusable frame slot on ready. Return ready, timeout, end, cancelled, closed or failed as a scalar String. Timeout is not end of stream; inspect error on failed. |
video.close(value: VideoSource) | Unit | Idempotently close this source and all aliases; join its worker and wake readers. |
video.state(source: VideoSource) | String | Inspect the source state without retaining frame data. |
video.backend(source: VideoSource) | String | Inspect the source backend without retaining frame data. |
video.captured(source: VideoSource) | Int64 | Inspect the source captured without retaining frame data. |
video.delivered(source: VideoSource) | Int64 | Inspect the source delivered without retaining frame data. |
video.dropped(source: VideoSource) | Int64 | Inspect the source dropped without retaining frame data. |
video.queued_frames(source: VideoSource) | Int64 | Inspect the source queued frames without retaining frame data. |
video.queued_bytes(source: VideoSource) | Int64 | Inspect the source queued bytes without retaining frame data. |
video.snapshot_bytes(source: VideoSource) | Int64 | Inspect the source snapshot bytes without retaining frame data. |
video.error(source: VideoSource) | String | Return the source failure description with credentials redacted. |
video.snapshot(value: VideoSource, frame: VideoFrameSlot) | VideoFrame | Take an immutable retained frame copy under the source aggregate snapshot budget. |
video.snapshot(value: VideoFrameSlot) | VideoFrame | Take an immutable retained copy under the originating source snapshot budget; retained frames survive source close. |
video.ready(frame: VideoFrameSlot) | Bool | Report whether this native frame contains pixels; a timeout does not turn its previous contents into a fresh frame. |
video.width(frame: VideoFrameSlot) | Int64 | Inspect frame width. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.height(frame: VideoFrameSlot) | Int64 | Inspect frame height. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.stride(frame: VideoFrameSlot) | Int64 | Inspect frame stride. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.source_id(frame: VideoFrameSlot) | Int64 | Inspect frame source id. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.session_id(frame: VideoFrameSlot) | Int64 | Inspect frame session id. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.sequence(frame: VideoFrameSlot) | Int64 | Inspect frame sequence. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.pts_ns(frame: VideoFrameSlot) | Int64 | Inspect frame pts ns. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.received_ns(frame: VideoFrameSlot) | Int64 | Inspect frame received ns. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.has_pts(frame: VideoFrameSlot) | Bool | Inspect frame has pts. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.timestamp_origin(frame: VideoFrameSlot) | String | Inspect frame timestamp origin. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.pixel_format(frame: VideoFrameSlot) | String | Inspect frame pixel format. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.memory(frame: VideoFrameSlot) | String | Inspect frame memory. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.pixel(frame: VideoFrameSlot, x: Int64, y: Int64, channel: Int64) | Int64 | Read a checked RGB8 channel value at zero based x,y and channel 0,1,2. Intended for inspection, not pixel by pixel inference. |
video.ready(frame: VideoFrame) | Bool | Report whether this native frame contains pixels; a timeout does not turn its previous contents into a fresh frame. |
video.width(frame: VideoFrame) | Int64 | Inspect frame width. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.height(frame: VideoFrame) | Int64 | Inspect frame height. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.stride(frame: VideoFrame) | Int64 | Inspect frame stride. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.source_id(frame: VideoFrame) | Int64 | Inspect frame source id. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.session_id(frame: VideoFrame) | Int64 | Inspect frame session id. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.sequence(frame: VideoFrame) | Int64 | Inspect frame sequence. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.pts_ns(frame: VideoFrame) | Int64 | Inspect frame pts ns. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.received_ns(frame: VideoFrame) | Int64 | Inspect frame received ns. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.has_pts(frame: VideoFrame) | Bool | Inspect frame has pts. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.timestamp_origin(frame: VideoFrame) | String | Inspect frame timestamp origin. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.pixel_format(frame: VideoFrame) | String | Inspect frame pixel format. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.memory(frame: VideoFrame) | String | Inspect frame memory. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds. |
video.pixel(frame: VideoFrame, x: Int64, y: Int64, channel: Int64) | Int64 | Read a checked RGB8 channel value at zero based x,y and channel 0,1,2. Intended for inspection, not pixel by pixel inference. |
video.record(path: String, width: Int64, height: Int64, fps: Float64 = 30.0) | VideoWriter | Create a new .mkv Matroska/FFV1 lossless CPU RGB8 recorder. Writes are synchronous and preserve increasing source timestamps relative to the first timestamp; missing timestamps use the declared FPS. One source session per writer; existing paths are rejected. |
video.write(writer: VideoWriter, frame: VideoFrameSlot) | Unit | Synchronously encode one frame of the declared geometry. The caller owns scheduling; slow recording blocks this call. |
video.write(writer: VideoWriter, frame: VideoFrame) | Unit | Synchronously encode one frame of the declared geometry. The caller owns scheduling; slow recording blocks this call. |
video.close(value: VideoWriter) | Unit | Finalize the recording container. All aliases share writer closure; errors remain visible. |
video.frames_written(writer: VideoWriter) | Int64 | Return successfully written frames. |
video.snapshot_url(url: String, queue_frames: Int64 = 2, memory_mb: Int64 = 128, timeout_ms: Int64 = 3000, ca_file: String = "") | VideoSource | Fetch one finite HTTP(S) camera snapshot through a bounded, verified request; no redirects. Authorization, when supplied, is an opaque SecretRef containing a raw bearer token; the adapter constructs the Authorization header and requires HTTPS. ca_file is empty for system trust or an explicit trusted CA bundle; TLS verification is mandatory. |
video.snapshot_url(url: String, authorization: SecretRef, queue_frames: Int64 = 2, memory_mb: Int64 = 128, timeout_ms: Int64 = 3000, ca_file: String = "") | VideoSource | Fetch one finite HTTP(S) camera snapshot through a bounded, verified request; no redirects. Authorization, when supplied, is an opaque SecretRef containing a raw bearer token; the adapter constructs the Authorization header and requires HTTPS. ca_file is empty for system trust or an explicit trusted CA bundle; TLS verification is mandatory. |
Vision functions
| Signature | Result | Contract |
|---|---|---|
vision.preprocess(width: Int64, height: Int64, resize: String = "letterbox", filter: String = "bilinear", scale: Float64 = 1.0 / 255.0, pad: Float64 = 114.0) | VisionPlan | Create an immutable RGB8 preprocessing plan for detached CPU Float32 NCHW output. Resize is letterbox, stretch or crop; filter is nearest or bilinear; normalization uses (pixel*scale mean)/std. |
vision.normalize(plan: VisionPlan, mean_r: Float64, mean_g: Float64, mean_b: Float64, std_r: Float64, std_g: Float64, std_b: Float64) | VisionPlan | Return a plan with explicit finite per channel RGB mean and positive standard deviation. Retain the returned immutable plan. |
vision.input_slot(plan: VisionPlan) | VisionInput | Allocate one reusable native preprocessing slot. Copies alias its updates; previously returned Tensor values remain valid snapshots. |
vision.prepare_into(plan: VisionPlan, frame: VideoFrameSlot, input: VisionInput) | Unit | Prepare RGB8 pixels into a reusable native slot and retain exact source/frame geometry for coordinate recovery. |
vision.prepare_into(plan: VisionPlan, frame: VideoFrame, input: VisionInput) | Unit | Prepare RGB8 pixels into a reusable native slot and retain exact source/frame geometry for coordinate recovery. |
vision.ready(input: VisionInput) | Bool | Report whether the input slot contains a prepared frame. |
vision.tensor(input: VisionInput) | Tensor | Return a detached CPU Float32 Tensor [1,3,H,W]. For explicit accelerator transfer, import aner.nn and use the Tensor.to method or nn.to; this operation performs no automatic transfer. |
vision.features(input: VisionInput) | Tensor | Return flattened [1,3HW] CPU Float32 features for compatible classical or dense models; preprocessing must match training. |
vision.width(value: VisionPlan) | Int64 | Return model input width. |
vision.height(value: VisionPlan) | Int64 | Return model input height. |
vision.summary(value: VisionPlan) | String | Return a bounded native descriptor without retaining pixel or tensor copies. |
vision.width(value: VisionInput) | Int64 | Return original source frame width. |
vision.height(value: VisionInput) | Int64 | Return original source frame height. |
vision.summary(value: VisionInput) | String | Return a bounded native descriptor without retaining pixel or tensor copies. |
vision.detections(max_detections: Int64 = 300) | DetectionSet | Create a reusable bounded native detection output slot. This does not load or execute a detector. |
vision.postprocess_into(rows: Tensor, input: VisionInput, output: DetectionSet, score_threshold: Float64 = 0.25, iou_threshold: Float64 = 0.45, max_candidates: Int64 = 10000) | Unit | Validate CPU Nx6 xyxy/score/class rows in model input pixels, undo preprocessing, clip and run deterministic class aware greedy NMS. It consumes decoded detections, not arbitrary raw model output. |
vision.count(detections: DetectionSet) | Int64 | Return retained detection count. |
vision.x1(detections: DetectionSet, index: Int64) | Float64 | Read the checked x1 for one retained detection; coordinates are original source frame pixel corners. |
vision.y1(detections: DetectionSet, index: Int64) | Float64 | Read the checked y1 for one retained detection; coordinates are original source frame pixel corners. |
vision.x2(detections: DetectionSet, index: Int64) | Float64 | Read the checked x2 for one retained detection; coordinates are original source frame pixel corners. |
vision.y2(detections: DetectionSet, index: Int64) | Float64 | Read the checked y2 for one retained detection; coordinates are original source frame pixel corners. |
vision.score(detections: DetectionSet, index: Int64) | Float64 | Read the checked score for one retained detection; coordinates are original source frame pixel corners. |
vision.class_id(detections: DetectionSet, index: Int64) | Int64 | Read the checked class_id for one retained detection; coordinates are original source frame pixel corners. |
vision.summary(value: DetectionSet) | String | Return a bounded descriptor containing the retained detection count and configured capacity. |
vision.source_id(value: VisionInput) | Int64 | Return the originating frame source id. |
vision.session_id(value: VisionInput) | Int64 | Return the originating frame session id. |
vision.sequence(value: VisionInput) | Int64 | Return the originating frame sequence. |
vision.source_id(value: DetectionSet) | Int64 | Return the originating frame source id. |
vision.session_id(value: DetectionSet) | Int64 | Return the originating frame session id. |
vision.sequence(value: DetectionSet) | Int64 | Return the originating frame sequence. |
Shapes, timing and errors
VisionInput.tensor() returns a shared detached [1,3,H,W] CPU Float32 tensor. features() makes an explicitly owned detached [1,3*H*W] CPU Float32 flatten copy for compatible classical estimators. Neither operation fits a preprocessing transform or grants training membership. Calling tensor/geometry accessors before a successful preparation fails.
pts_ns is a source presentation timestamp in nanoseconds and must be interpreted together with has_pts and timestamp_origin. received_ns uses the host monotonic clock. Source and session IDs distinguish origins; sequence numbers alone are not globally unique. Identity accessors on VisionInput and DetectionSet refer to the retained preparation mapping.
read_into returns ready, timeout, end, cancelled, closed or failed. A non ready outcome invalidates the slot while allowing its allocated capacity to be reused. Accessing invalid pixels/metadata fails. Native video errors use R4301; vision errors use R4302. Argument/type checking is performed before execution. Mutable slots require one coordinated caller; concurrent mutation and readout are unsupported.
Recording accepts only matching frame geometry from one source/session and explicitly finalizes its container. Backend and timestamp behavior are described in the recording contract. Model inference, arbitrary decoder output interpretation, pretrained model downloads and tracking are outside these signatures.