Browse documentation
aner.video · Reference

Video and vision parameter reference

Inspect constructor defaults, frame lifetime, preprocessing variables, read outcomes and supplied box postprocessing contracts.

ImplementedAner 0.1.0 or newer

These 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

TypeOwnership and mutation
VideoSourceShared native session; aliases share queue, counters and close
VideoFrameSlotReusable mutable RGB8 CPU storage; aliases share updates
VideoFrameImmutable copied snapshot, charged to its source snapshot budget
VideoWriterShared recording session with explicit finalization
VisionPlanImmutable preprocessing recipe
VisionInputReusable current NCHW tensor and original frame mapping
DetectionSetReusable bounded box results retaining frame identity

Parameter limits and meanings

ParameterContract
width, height on video sourcesPositive dimensions, at most 32768 each; packed RGB output must also fit its per frame budget
framesNonnegative synthetic frame count; zero runs until stopped
fpsSynthetic/recording: finite positive rate up to 1000. Camera: zero omits the rate preference; otherwise the same bound applies
realtimePace synthetic acquisition and permit bounded latest frame delivery
queue_framesInteger 1..256; limits pending frames
memory_mbSource queues: integer 1..4096; frame slots: 1..1024. Units are MiB (1048576 bytes), despite the short argument name
timeout_msCaller wait: integer 0..3600000 (zero polls). Backend I/O deadline: 1..3600000; worker operation continues after a caller timeout
deviceOS native capture locator; default selects the adapter default
pathLocal input path, or a new .mkv destination for recording
urlExplicit supported endpoint; userinfo/fragments and recognized credential like query names are rejected. Bounded ordinary selectors are accepted
ca_fileEmpty for system trust, or a trusted CA bundle path; hostname/peer verification stays enabled
authorizationOpaque SecretRef resolving a raw bearer token; snapshot only and HTTPS only. The adapter constructs the header
x, y, channelZero based pixel indexes; channel 0..2 means R,G,B
vision output dimensionsEach 1..4096; at most 16777216 Float32 elements across all three channels
resizeletterbox, stretch or crop
filternearest or bilinear
scaleFinite positive channel multiplier; applied before mean/std
padFinite RGB8 domain value in [0,255]
mean_r/g/bFinite channel means after scale
std_r/g/bFinite positive channel divisors
max_detectionsInteger 1..4096; retained output capacity
score_threshold, iou_thresholdFinite values in [0,1]
max_candidatesInteger 1..65536; admitted Nx6 row bound
indexZero 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

SignatureResultContract
video.available()BoolReport whether this build includes the installed FFmpeg video backend. Synthetic sources remain available without it.
video.camera_backend()StringReturn the compiled OS camera adapter name without opening a camera.
video.devices()StringReturn bounded device enumeration JSON; unsupported enumeration is explicit.
video.frame_slot(memory_mb: Int64 = 64)VideoFrameSlotCreate 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)VideoSourceCreate 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)VideoSourceDecode 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)VideoSourceOpen 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)VideoSourceOpen 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)StringReplace 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)UnitIdempotently close this source and all aliases; join its worker and wake readers.
video.state(source: VideoSource)StringInspect the source state without retaining frame data.
video.backend(source: VideoSource)StringInspect the source backend without retaining frame data.
video.captured(source: VideoSource)Int64Inspect the source captured without retaining frame data.
video.delivered(source: VideoSource)Int64Inspect the source delivered without retaining frame data.
video.dropped(source: VideoSource)Int64Inspect the source dropped without retaining frame data.
video.queued_frames(source: VideoSource)Int64Inspect the source queued frames without retaining frame data.
video.queued_bytes(source: VideoSource)Int64Inspect the source queued bytes without retaining frame data.
video.snapshot_bytes(source: VideoSource)Int64Inspect the source snapshot bytes without retaining frame data.
video.error(source: VideoSource)StringReturn the source failure description with credentials redacted.
video.snapshot(value: VideoSource, frame: VideoFrameSlot)VideoFrameTake an immutable retained frame copy under the source aggregate snapshot budget.
video.snapshot(value: VideoFrameSlot)VideoFrameTake an immutable retained copy under the originating source snapshot budget; retained frames survive source close.
video.ready(frame: VideoFrameSlot)BoolReport whether this native frame contains pixels; a timeout does not turn its previous contents into a fresh frame.
video.width(frame: VideoFrameSlot)Int64Inspect frame width. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.height(frame: VideoFrameSlot)Int64Inspect frame height. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.stride(frame: VideoFrameSlot)Int64Inspect frame stride. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.source_id(frame: VideoFrameSlot)Int64Inspect frame source id. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.session_id(frame: VideoFrameSlot)Int64Inspect frame session id. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.sequence(frame: VideoFrameSlot)Int64Inspect frame sequence. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.pts_ns(frame: VideoFrameSlot)Int64Inspect frame pts ns. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.received_ns(frame: VideoFrameSlot)Int64Inspect frame received ns. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.has_pts(frame: VideoFrameSlot)BoolInspect frame has pts. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.timestamp_origin(frame: VideoFrameSlot)StringInspect frame timestamp origin. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.pixel_format(frame: VideoFrameSlot)StringInspect frame pixel format. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.memory(frame: VideoFrameSlot)StringInspect frame memory. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.pixel(frame: VideoFrameSlot, x: Int64, y: Int64, channel: Int64)Int64Read 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)BoolReport whether this native frame contains pixels; a timeout does not turn its previous contents into a fresh frame.
video.width(frame: VideoFrame)Int64Inspect frame width. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.height(frame: VideoFrame)Int64Inspect frame height. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.stride(frame: VideoFrame)Int64Inspect frame stride. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.source_id(frame: VideoFrame)Int64Inspect frame source id. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.session_id(frame: VideoFrame)Int64Inspect frame session id. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.sequence(frame: VideoFrame)Int64Inspect frame sequence. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.pts_ns(frame: VideoFrame)Int64Inspect frame pts ns. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.received_ns(frame: VideoFrame)Int64Inspect frame received ns. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.has_pts(frame: VideoFrame)BoolInspect frame has pts. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.timestamp_origin(frame: VideoFrame)StringInspect frame timestamp origin. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.pixel_format(frame: VideoFrame)StringInspect frame pixel format. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.memory(frame: VideoFrame)StringInspect frame memory. Timestamps retain their stated origin; receipt time is host monotonic nanoseconds.
video.pixel(frame: VideoFrame, x: Int64, y: Int64, channel: Int64)Int64Read 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)VideoWriterCreate 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)UnitSynchronously encode one frame of the declared geometry. The caller owns scheduling; slow recording blocks this call.
video.write(writer: VideoWriter, frame: VideoFrame)UnitSynchronously encode one frame of the declared geometry. The caller owns scheduling; slow recording blocks this call.
video.close(value: VideoWriter)UnitFinalize the recording container. All aliases share writer closure; errors remain visible.
video.frames_written(writer: VideoWriter)Int64Return successfully written frames.
video.snapshot_url(url: String, queue_frames: Int64 = 2, memory_mb: Int64 = 128, timeout_ms: Int64 = 3000, ca_file: String = "")VideoSourceFetch 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 = "")VideoSourceFetch 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

SignatureResultContract
vision.preprocess(width: Int64, height: Int64, resize: String = "letterbox", filter: String = "bilinear", scale: Float64 = 1.0 / 255.0, pad: Float64 = 114.0)VisionPlanCreate 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)VisionPlanReturn a plan with explicit finite per channel RGB mean and positive standard deviation. Retain the returned immutable plan.
vision.input_slot(plan: VisionPlan)VisionInputAllocate 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)UnitPrepare 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)UnitPrepare RGB8 pixels into a reusable native slot and retain exact source/frame geometry for coordinate recovery.
vision.ready(input: VisionInput)BoolReport whether the input slot contains a prepared frame.
vision.tensor(input: VisionInput)TensorReturn 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)TensorReturn flattened [1,3HW] CPU Float32 features for compatible classical or dense models; preprocessing must match training.
vision.width(value: VisionPlan)Int64Return model input width.
vision.height(value: VisionPlan)Int64Return model input height.
vision.summary(value: VisionPlan)StringReturn a bounded native descriptor without retaining pixel or tensor copies.
vision.width(value: VisionInput)Int64Return original source frame width.
vision.height(value: VisionInput)Int64Return original source frame height.
vision.summary(value: VisionInput)StringReturn a bounded native descriptor without retaining pixel or tensor copies.
vision.detections(max_detections: Int64 = 300)DetectionSetCreate 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)UnitValidate 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)Int64Return retained detection count.
vision.x1(detections: DetectionSet, index: Int64)Float64Read the checked x1 for one retained detection; coordinates are original source frame pixel corners.
vision.y1(detections: DetectionSet, index: Int64)Float64Read the checked y1 for one retained detection; coordinates are original source frame pixel corners.
vision.x2(detections: DetectionSet, index: Int64)Float64Read the checked x2 for one retained detection; coordinates are original source frame pixel corners.
vision.y2(detections: DetectionSet, index: Int64)Float64Read the checked y2 for one retained detection; coordinates are original source frame pixel corners.
vision.score(detections: DetectionSet, index: Int64)Float64Read the checked score for one retained detection; coordinates are original source frame pixel corners.
vision.class_id(detections: DetectionSet, index: Int64)Int64Read the checked class_id for one retained detection; coordinates are original source frame pixel corners.
vision.summary(value: DetectionSet)StringReturn a bounded descriptor containing the retained detection count and configured capacity.
vision.source_id(value: VisionInput)Int64Return the originating frame source id.
vision.session_id(value: VisionInput)Int64Return the originating frame session id.
vision.sequence(value: VisionInput)Int64Return the originating frame sequence.
vision.source_id(value: DetectionSet)Int64Return the originating frame source id.
vision.session_id(value: DetectionSet)Int64Return the originating frame session id.
vision.sequence(value: DetectionSet)Int64Return 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.

Aner documentation · Reference and guides