#!/usr/bin/env python3 """完整官方源的原MEMO索引时钟与解码器原生PTS核对,检查所有已摄入帧。""" import collections import concurrent.futures import json from pathlib import Path import sys ROOT=Path(__file__).resolve().parents[1] sys.path.insert(0,str(ROOT));sys.path.insert(0,str(ROOT/'scripts'));sys.path.insert(0,str(ROOT/'repos/MEMO')) from download_assets import atomic,sha def inspect(item): import decord import numpy as np from memo.stage1.sampling import build_sample_indices key,questions=item;benchmark,source=key from cgvm.sources import source_plan sources,_,_=source_plan(benchmark) path=ROOT/sources[source]['path'] try: reader=decord.VideoReader(str(path),ctx=decord.cpu(0),num_threads=1) fps=float(reader.get_avg_fps());indices=build_sample_indices(len(reader),fps,1.,anchor_end=False) pts=np.asarray(reader.get_frame_timestamp(indices))[:,0] clock=np.asarray(indices,dtype=np.float64)/fps checks=[];future=0 for q in questions: visible=clock<=q['query_time']+1e-6 violation=visible & (pts>q['query_time']+1e-6) count=int(violation.sum());future+=count checks.append(dict(id=q['id'],query_time=q['query_time'],ingested_frames=int(visible.sum()), future_native_PTS_frames=count,max_ingested_actual_PTS=float(pts[visible].max()) if visible.any() else None, future_examples=[dict(native_index=int(indices[i]),MEMO_time=float(clock[i]),native_PTS=float(pts[i])) for i in np.where(violation)[0][:16]])) maxqt=max(q['query_time'] for q in questions);observed=clock<=maxqt+1e-6 return dict(benchmark=benchmark,source_video=source,media_path=str(path.relative_to(ROOT)), media_sha256=sources[source]['media_sha256'],status='passed' if future==0 and np.all(np.diff(pts)>=0) else 'native_time_violation', native_fps=fps,native_frames=len(reader),sampled_frames=len(indices),future_native_PTS_frame_query_pairs=future, max_abs_observed_clock_PTS_difference=float(np.abs(pts[observed]-clock[observed]).max()),checks=checks, native_timestamp_dtype=str(pts.dtype)) except Exception as exc:return dict(benchmark=benchmark,source_video=source,status='failed',error=type(exc).__name__+':'+str(exc)) def main(): import torch torch.set_num_threads(1) groups=collections.defaultdict(list) for line in (ROOT/'manifests/eval_questions.jsonl').open(): q=json.loads(line);groups[(q['benchmark'],q['source_video'])].append({key:q[key] for key in ('id','query_time')}) with concurrent.futures.ThreadPoolExecutor(max_workers=16) as pool:result=list(pool.map(inspect,sorted(groups.items()))) value=dict(passed=all(r['status']=='passed' for r in result),scope='all_official_query_prefix_ingested_1fps_indices_native_PTS_metadata_not_RGB_decode', source_videos=len(groups),queries=sum(map(len,groups.values())),videos=result, manifest_sha256=sha(ROOT/'manifests/eval_questions.jsonl'),sampling_code_sha256=sha(ROOT/'repos/MEMO/memo/stage1/sampling.py'), timestamp_api='decord.VideoReader.get_frame_timestamp(indices)[:,0]',time_tolerance_seconds=1e-6, sampled_clock='locked_MEMO_native_index_divided_by_original_avg_fps; no_prefix_resampling') atomic(ROOT/'provenance/native_PTS_full_audit.json',value) print(json.dumps(dict(passed=value['passed'],source_videos=len(result),queries=value['queries'], violations=[{k:v for k,v in r.items() if k!='checks'} for r in result if r['status']!='passed']),ensure_ascii=False)) if not value['passed']:raise SystemExit(1) if __name__=='__main__':main()