Reuse global history frames in overlap working memory
This commit is contained in:
@@ -826,15 +826,17 @@ class CausalSourceAV:
|
||||
}
|
||||
|
||||
|
||||
class EndpointAlignedAV:
|
||||
"""Working-window view whose final visual sample is exactly current time.
|
||||
class GlobalHistoryCurrentAV:
|
||||
"""Working-window view with cached global history plus the current frame.
|
||||
|
||||
Complete cached blocks use the source reader's fixed global half-open grid,
|
||||
for example ``[18.0, 18.5, 19.0, 19.5]`` for ``[18,20)`` at 2 FPS. A
|
||||
two-second working interval ending at ``t`` instead uses
|
||||
``[t-1.5, t-1.0, t-0.5, t]``. The number of visual samples therefore
|
||||
stays matched while the working branch explicitly observes the current
|
||||
causal frame. Audio remains the exact half-open slice ``[start,end)``.
|
||||
two-second working interval ending at ``t`` uses the latest global-grid
|
||||
samples at or before ``t-1.5``, ``t-1.0``, and ``t-0.5``, followed by the
|
||||
current causal frame at ``t``. At ``t=20.4`` this is
|
||||
``[18.5, 19.0, 19.5, 20.4]``. Historical pixels therefore reuse the same
|
||||
source-frame cache as complete blocks and only the current frame advances
|
||||
at 5 Hz. Audio remains the exact half-open slice ``[start,end)``.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@@ -868,13 +870,16 @@ class EndpointAlignedAV:
|
||||
)
|
||||
count = max(1, int(math.ceil(duration * self.fps - EPSILON)))
|
||||
count = min(count, self.max_frames)
|
||||
first = end - (count - 1) / self.fps
|
||||
if first < start - EPSILON:
|
||||
raise RuntimeError(
|
||||
f"Endpoint-aligned grid starts before its interval: "
|
||||
f"{first:g} < {start:g}"
|
||||
)
|
||||
return [first + index / self.fps for index in range(count)]
|
||||
history_times = []
|
||||
for slots_before_current in range(count - 1, 0, -1):
|
||||
desired_time = end - slots_before_current / self.fps
|
||||
# Quantize only historical samples to the session-global grid.
|
||||
# During the short initial warm-up, clamp to the causal interval
|
||||
# start rather than selecting media from before the requested
|
||||
# working window.
|
||||
grid_index = int(math.floor(desired_time * self.fps + EPSILON))
|
||||
history_times.append(max(start, grid_index / self.fps))
|
||||
return [*history_times, end]
|
||||
|
||||
def frames(self, start: float, end: float) -> list[Any]:
|
||||
frames = [
|
||||
@@ -891,19 +896,23 @@ class EndpointAlignedAV:
|
||||
|
||||
def metadata(self) -> dict[str, Any]:
|
||||
return {
|
||||
"visual_sampling": "endpoint_aligned_latest_source_pts_not_after_tick",
|
||||
"visual_sampling": "global_grid_history_plus_current_causal_frame",
|
||||
"audio_interval": "half_open_[start,end)",
|
||||
"working_memory_seconds": self.max_interval_seconds,
|
||||
"output_video_fps": self.fps,
|
||||
"full_window_frame_count": self.max_frames,
|
||||
"full_window_relative_video_times": [
|
||||
"desired_history_offsets_seconds": [
|
||||
-(self.max_frames - 1 - index) / self.fps
|
||||
for index in range(self.max_frames)
|
||||
for index in range(self.max_frames - 1)
|
||||
],
|
||||
"current_frame_offset_seconds": 0.0,
|
||||
"history_timestamp_quantization": "floor_to_session_global_grid",
|
||||
"includes_current_video_frame": True,
|
||||
"oldest_visual_tick_replaced_by_current": True,
|
||||
"timestamp_note": (
|
||||
"video is endpoint-aligned while audio retains the full "
|
||||
"historical video targets are quantized causally to the "
|
||||
"global grid for decoder/cache reuse; the final video sample "
|
||||
"is exactly current time while audio retains the full "
|
||||
"half-open working interval"
|
||||
),
|
||||
}
|
||||
@@ -1384,7 +1393,7 @@ def main(
|
||||
show_progress=not args.no_progress,
|
||||
)
|
||||
else:
|
||||
working_grid_av = EndpointAlignedAV(
|
||||
working_grid_av = GlobalHistoryCurrentAV(
|
||||
reader,
|
||||
max_interval_seconds=args.working_memory_seconds,
|
||||
)
|
||||
@@ -1427,7 +1436,7 @@ def main(
|
||||
if args.mode == "open-stream-replay"
|
||||
else (
|
||||
"serialized_cached_complete_blocks_then_overlapping_"
|
||||
"endpoint_aligned_recent_recap"
|
||||
"global_history_current_frame_recent_recap"
|
||||
)
|
||||
)
|
||||
),
|
||||
@@ -1444,7 +1453,7 @@ def main(
|
||||
"source_manifest_record": manifest_record,
|
||||
"direct_media": reader.metadata(),
|
||||
"video_sampling_grid": (
|
||||
"fixed_global_half_open_plus_endpoint_aligned_working_recap"
|
||||
"fixed_global_half_open_plus_global_history_current_frame_recap"
|
||||
if args.mode == "overlap-working-memory"
|
||||
else "direct_pts_causal_global_grid_half_open_with_tail_duplication"
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user