an.frame_clock#
The frame clock: WHEN each output frame samples scene time.
A render has always sampled frame i at exactly i / fps — one instant,
on a perfect grid. A real camera does neither: its shutter stays open for part
of the frame period (so a moving object smears), and its capture instants
wander around the nominal grid (so the timestamp a frame carries is not quite
when it was taken). Anything that wants to measure motion from video — the
sub-frame impact estimators cutan.impacts exists to score — needs both, and
needs to know exactly what was done.
FrameClock is that model as data. FrameClock.frames() returns one
CapturedFrame per output frame, carrying the exposure interval and the
instants integrated over it; FrameClock.sample_times() is the projection
the renderer consumes through RenderContext.frame_samples. One object feeds
both the render and the ground truth, so the two cannot disagree about when a
frame was taken.
It also owns the GRIDS a shot is laid onto, the pure rules every layer shares
(the IR’s camera, the stage’s compiler and solve): frame_times() (every
frame, the end included), step_times() (a stepped shot’s pose grid,
an#89; the rule lives in an.timing.grid, an#784), grid_times() (one or the other, the solve’s grid) and
camera_grid() (an#626), the instants a camera the runtime cannot
evaluate itself — a follow, a dolly — is keyed at so that every instant the
render samples, a shutter’s sub-frame ones included, lands on an exact key.
The default clock is the old behaviour exactly — no exposure, no jitter, one
sample at i / fps:
>>> FrameClock(fps=4).sample_times(1.0)
((0.0,), (0.25,), (0.5,), (0.75,))
A 180-degree shutter (exposure=0.5) integrates the first half of each frame
period, sampled at the midpoints of samples equal sub-intervals:
>>> FrameClock(fps=4, exposure=0.5, samples=2).sample_times(0.5)
((0.03125, 0.09375), (0.28125, 0.34375))
>>> f = FrameClock(fps=4, exposure=0.5, samples=2).frames(0.5)[1]
>>> (f.t_nominal, f.t_open, f.t_close, f.t_mid)
(0.25, 0.25, 0.375, 0.3125)
Capture jitter moves each frame’s exposure as a unit, never out of order:
>>> clock = FrameClock(fps=30, jitter_sd=0.004, seed=7)
>>> opens = [f.t_open for f in clock.frames(2.0)]
>>> all(b > a for a, b in zip(opens, opens[1:]))
True
>>> clock.frames(2.0) == clock.frames(2.0) # seeded: the same clock twice
True
Module Attributes
Sub-samples integrated per frame when the shutter is open and the caller did not say how many. |
|
A frame's capture offset is clamped to this fraction of the slack between one exposure closing and the next opening, on each side. |
|
Report noise is clamped to this fraction of the frame period, each side, so two neighbouring reported timestamps can never cross on a regular grid. |
|
a shutter sample that IS a frame up to float noise adds no key beside it (two keys a femtosecond apart would only divide by that femtosecond). |
Functions
|
The ONE sampler for a non-affine camera — a follow, a dolly, anything the runtime cannot evaluate from a few eased keys (an#626). |
|
Frames in a render of |
|
The time of every frame a |
|
A shot's own grid: every frame ( |
|
Clip-local times at which a stepped tween updates its pose (an#89). |
Classes
|
Where a camera the runtime cannot evaluate itself is keyed (an#626). |
|
One output frame: when its exposure opened and closed, and what it saw. |
|
A camera's timing, as data. |
Exceptions
A frame clock that cannot describe a camera. |
- class an.frame_clock.CameraGrid(times, base, easing)[source]#
Bases:
objectWhere a camera the runtime cannot evaluate itself is keyed (an#626).
times: the key instants, sorted.easing: the keys’ easing —"linear"on ones,"step"on a stepped shot (the camera holds between keys as a stepped tween holds between poses).base: the grid the camera is COMPUTED on — every frame, and every step instant on a stepped shot — before the render’s sample instants are added (a follow’s lag runs over it);timesis a superset of it.
- class an.frame_clock.CapturedFrame(index, t_nominal, t_open, t_close, samples, t_reported)[source]#
Bases:
objectOne output frame: when its exposure opened and closed, and what it saw.
t_nominalisindex / fps— what a constant-rate container (an mp4) says the frame’s time is.samplesare the instants actually rendered and averaged into it;t_midis the middle of the exposure, the single best instant to attribute a blurred frame to.t_reportedis the timestamp a capture pipeline hands downstream: nominal or actual, per the clock’stimestampssetting.
- an.frame_clock.DEFAULT_EXPOSURE_SAMPLES: int = 8#
Sub-samples integrated per frame when the shutter is open and the caller did not say how many. Eight midpoint samples put the smear of an object crossing 100 px in one exposure at steps of ~12 px — continuous to a tracker, cheap to render (each sample is one screenshot).
- class an.frame_clock.FrameClock(fps=30.0, exposure=0.0, samples=None, jitter_sd=0.0, phase=0.0, timestamps='nominal', report_noise_sd=0.0, seed=0)[source]#
Bases:
objectA camera’s timing, as data. Every field defaults to the ideal camera.
fps: nominal frame rate (need not be an integer: 29.97 is a camera).exposure: fraction of the frame period the shutter is open, in[0, 1]; 0 is an instantaneous sample, 0.5 a 180-degree shutter.samples: instants integrated per open exposure (midpoint rule);Nonemeans 1 whenexposure == 0andDEFAULT_EXPOSURE_SAMPLESotherwise.jitter_sd: standard deviation, in seconds, of each frame’s CAPTURE offset from the nominal grid — the frame really is taken early or late. Gaussian, clamped atmax_jitterso frames never overlap; ajitter_sdabove half that clamp is refused rather than silently shrunk (atexposure=1there is no room for any).phase: seconds added to every capture instant — the camera clock’s sub-frame offset from scene time, in(-1/fps, 1/fps).timestamps: the base ofCapturedFrame.t_reported—"nominal"(index / fps, what a naive tick loop or an mp4 reports) or"actual"(t_open, what a capture API with real timestamps reports).report_noise_sd: Gaussian noise, in seconds, added to the REPORTED timestamp only — regular capture, noisy clock (a browser frame callback). Clamped atMAX_REPORT_NOISE_FRACTIONof a frame period, with the same refuse-rather-than-shrink rule asjitter_sd, and reported timestamps must still increase: a real frame clock never runs backwards.seed: the random streams (capture jitter and report noise are independent draws from it).Every instant is clipped into
[0, duration], because a render cannot sample a scene outside its own timeline; the clipped values are whatframes()returns and what gets rendered.- frames(duration)[source]#
One
CapturedFrameper output frame of adurationrender.- Return type:
- property max_jitter: float#
The clamp on a frame’s capture offset, in seconds.
>>> round(FrameClock(fps=10, exposure=0.5).max_jitter, 9) 0.0245
- exception an.frame_clock.FrameClockError[source]#
Bases:
ValueErrorA frame clock that cannot describe a camera.
- an.frame_clock.MAX_JITTER_FRACTION: float = 0.49#
A frame’s capture offset is clamped to this fraction of the slack between one exposure closing and the next opening, on each side. Below one half, so two neighbouring frames can each move toward the other by the full clamp and still not overlap: the clock never reorders frames, whatever
jitter_sdis.
- an.frame_clock.MAX_REPORT_NOISE_FRACTION: float = 0.24#
Report noise is clamped to this fraction of the frame period, each side, so two neighbouring reported timestamps can never cross on a regular grid.
- an.frame_clock.SAMPLE_MERGE_EPS: float = 1e-09#
a shutter sample that IS a frame up to float noise adds no key beside it (two keys a femtosecond apart would only divide by that femtosecond).
- Type:
Two camera key instants closer than this (s) are one key
- an.frame_clock.camera_grid(duration, *, fps, step_hz=None, frame_samples=None, sample_fps=None, merge_eps=1e-09)[source]#
The ONE sampler for a non-affine camera — a follow, a dolly, anything the runtime cannot evaluate from a few eased keys (an#626).
On ones (
step_hzunset) the camera is keyed at every frame (frame_times()), linearly. On a stepped shot it is keyed at every frame AND every step instant (step_times()), step-eased: it holds between keys as the stepped poses hold, so a step is a cut, not a one-frame ramp. The step grid alone would not do: a tween’s end lands off it, and the frames keep the camera exact where the target already moved.frame_samples(RenderContext.frame_samples, aFrameClock’ssample_times()) adds every instant the render actually samples — a shutter’s sub-frame ones, a jittered capture’s — clipped to[0, duration], so each lands on an exact key instead of between two. An instant withinmerge_epsof a key already there is that key.Noneadds nothing: the keys are exactly the frame grid they always were. They must describe THIS shot: one entry per frame (frame_count()) atsample_fps, the rate the render samples at (a camera’s 29.97, where the compiled grid’sfpsis rounded to 30;fpswhen unset), or aFrameClockError: another shot’s samples would key the camera at the wrong instants.>>> camera_grid(0.5, fps=4) CameraGrid(times=(0.0, 0.25, 0.5), base=(0.0, 0.25, 0.5), easing='linear') >>> camera_grid(0.5, fps=4, frame_samples=((0.0,), (0.3, 0.6))).times (0.0, 0.25, 0.3, 0.5) >>> g = camera_grid(0.5, fps=4, step_hz=3) >>> [round(t, 3) for t in g.times], g.easing, g.base == g.times ([0.0, 0.25, 0.333, 0.5], 'step', True) >>> len(camera_grid(20.0, fps=30, frame_samples=[(k / 29.97,) for k in range(599)], sample_fps=29.97).times) > 600 True >>> camera_grid(0.5, fps=4, frame_samples=((0.0,),)) Traceback (most recent call last): ... an.frame_clock.FrameClockError: frame_samples describes 1 frame(s) but a 0.5 s shot at 4 fps has 2: they are another shot's samples.
- Return type:
- an.frame_clock.frame_count(duration, fps)[source]#
Frames in a render of
durationseconds — the renderer’s own rule.>>> frame_count(2.0, 30), frame_count(0.01, 30) (60, 1)
- Return type:
- an.frame_clock.frame_times(duration, *, fps)[source]#
The time of every frame a
durationrender draws, the end included (k / fps, the renderer’s own expression, capped atduration).THE frame grid rule (an#626).
an.ir.camera.frame_timesis this very function re-exported, andan.stage.solve.frame_timesa thin wrapper overgrid_times(); neither restates it.>>> frame_times(0.5, fps=4) [0.0, 0.25, 0.5]
- an.frame_clock.grid_times(duration, *, fps, step_hz=None)[source]#
A shot’s own grid: every frame (
frame_times()), or its step grid (step_times()) understep_hz. What the solve runs at.>>> grid_times(0.1, fps=20) [0.0, 0.05, 0.1] >>> grid_times(0.25, fps=20, step_hz=10) [0.0, 0.1, 0.2, 0.25]
- an.frame_clock.step_times(start, duration, step_hz)[source]#
Clip-local times at which a stepped tween updates its pose (an#89).
The grid is SHOT-wide — multiples of
1/step_hzon the shot’s clock, shared by every tween in the shot — not the tween’s own: “on twos” means every character changes pose on the same frames, so a tween starting at 0.033 s updates at the next grid point, not 0.033 s later. (Shots compile independently, so the grid restarts at each cut.) Local 0 (the tween’s start) andduration(where the end value lands) are always present, so a tween shorter than one step is a single step to its end value.step_hzmust be positive: with a non-positive rate the walk below never reachesduration— an infinite loop, not an error — so it is refused.>>> step_times(0.0, 0.3, 10) [0.0, 0.1, 0.2, 0.3] >>> [round(t, 3) for t in step_times(0.05, 0.3, 10)] [0.0, 0.05, 0.15, 0.25, 0.3] >>> step_times(0.0, 0.02, 10) [0.0, 0.02]