diff --git a/research/TrackingMidpoint1.4.2.md b/research/TrackingMidpoint1.4.2.md new file mode 100644 index 0000000..01f6854 --- /dev/null +++ b/research/TrackingMidpoint1.4.2.md @@ -0,0 +1,19 @@ +# 1.4.2 中间帧启动与真实素材跟踪修复 + +本轮针对用户报告的“从中间没有反应、必须首帧正向、失去可靠跟踪”复现。FCP12.4使用当前正式1.4.1(26),把用户工程原生导出到本机验收缓存并导入独立副本,保留原项目、媒体与调色/蒙版设置。4K60源在25帧时间线:首帧正向保留65键;源时间3.68秒中间启动仅增加3键后失败,并弹出宿主分析错误。此前的合成视频检查不能替代这个真实素材问题。 + +## 修复 + +启动不再要求当前预览缓存存在且时间完全相等。FCP可以复用已渲染画面而不再进入插件渲染回调,因此缓存只作可选方向校对;实际FxAnalyzer首帧才是跟踪种子。仍检查分析起点范围、精确帧序、取消、冻结目标与迟到写入。新增原生检查覆盖无任何渲染缓存的中间启动、陈旧预览缓存和像素不同的预览缓存。 + +分析从完整宿主源图读取,按显示长宽比限制到1280×720,不放大小图;降采样前对源像素覆盖范围作低通,避免4K衣物细纹混叠为不一致运动。原调色渲染和输出分辨率不变。上一轮3840×2160是分析采样上限,本轮改用稳定的运动分析尺度;不再把“输入支持4K”写成仍逐像素4K分析。原生GPU检查使用3像素周期纹理,证明4K→720p先低通而非只抽中间像素。 + +仿射RANSAC细化容差改为3像素,并相应归一化残差置信度惩罚;只扩大容差而保留旧惩罚会在一致运动上过早低置信度停止。至少8内点、52%一致运动、最低0.3置信度、非线状分布、单步缩放/旋转和累计变换保护仍保留。未采用丢失后复制坐标伪造轨迹。新增确定平移、2.15像素非刚性残差和10%离群对应点的拟合检查;另有真实CPU/Metal图像光流、画面切换和平坦区域拒绝。 + +第一帧开始立即显示进度。失跟按特征不足、运动不一致、置信度、出画或变换问题区分,说明保留的可信帧数。普通失跟/主动取消停止时不再主动向宿主传递错误对象;引擎、无效源图和时序错误仍明确失败。是否消除FCP错误弹窗以正式宿主验收为准。 + +## 验证与边界 + +候选Release原生285项通过,包含真实Metal采样检查与三组新增中间启动回调检查;独立19项通过。用户同一素材的离线1280×720灰度分析覆盖首帧正向285帧、中间正向193帧、中间反向93帧。这里只承诺对应的分析范围完成,灰度解码与宿主半浮点源采样不完全相同,也不以“跟完”代替轮廓/漂移质量验证。正式安装后继续FCP验证同一素材和独立切换画面用例。 + +原始媒体、FCPXML快照、作者状态和解码帧均仅在本机验收缓存,普通Git只保存聚合结果与通用诊断源码。未修改父“大鱼调色盘”或Color Finale。不是人物分割/非刚性逐点描边;转身、遮挡、变形和出画仍可能需要手工调整后从当前帧继续。新增工具标量和透视/剪切等既有边界保持。 diff --git a/tools/verify_tool_tracking_followup.mm b/tools/verify_tool_tracking_followup.mm index 05ada66..c73ca55 100644 --- a/tools/verify_tool_tracking_followup.mm +++ b/tools/verify_tool_tracking_followup.mm @@ -29,6 +29,22 @@ static dy::GrayFrame frame(int w,int h,double tx=0,double ty=0,double angle=0, return f; } +// Isolate robust fitting and confidence from optical flow: coherent cloth-like +// 2.15px residuals plus 10% gross outliers, with a known mean translation. +class FitBudgetFlow final : public dy::FlowBackend { +public: + bool reset(const dy::GrayFrame&)override{return true;} + bool advance(const dy::GrayFrame&,const std::vector& points, + std::vector& out)override{ + for(size_t i=0;i1?[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]]:nil; + { + dy::Tracker tracker;tracker.setBackend(std::make_shared()); + auto image=frame(640,480);bool started=tracker.reset(image,{.5,.5,.85,.85,0}); + auto result=tracker.track(image);double ex=fabs(result.cx-(.5+2.25/640))*640,ey=fabs(result.cy-(.5-1.5/480))*480; + record(@"coherent-residual-fit-budget-with-ten-percent-outliers",started&&result.valid&&ex<.8&&ey<.8&&fabs(result.scaleX-1)<.02&&fabs(result.scaleY-1)<.02, + @{@"scope":@"Controlled correspondence unit test; not an optical-flow image oracle",@"inliers":@(result.inliers),@"matches":@(result.matches),@"confidence":@(result.confidence),@"xErrorPixels":@(ex),@"yErrorPixels":@(ey)}); + } for(int mode=0;mode<(library?2:1);mode++) { NSString *prefix=mode?@"metal":@"cpu"; auto setup=[&](dy::Tracker& tracker) { diff --git a/verification/TrackingMidpoint1.4.2.json b/verification/TrackingMidpoint1.4.2.json new file mode 100644 index 0000000..71408a2 --- /dev/null +++ b/verification/TrackingMidpoint1.4.2.json @@ -0,0 +1,218 @@ +{ + "status": "native-validated-awaiting-formal-host", + "version": "1.4.2", + "build": "27", + "baselineSource": "847a5ea99903c0b7427301c799e1c40f3fe6c5ad", + "nativeChecks": 285, + "independentChecks": [ + { + "pass": true, + "confidence": 0.38259220123291016, + "scope": "Controlled correspondence unit test; not an optical-flow image oracle", + "xErrorPixels": 0.09802246093748579, + "inliers": 270, + "yErrorPixels": 0.011092185974126423, + "name": "coherent-residual-fit-budget-with-ten-percent-outliers", + "matches": 300 + }, + { + "name": "cpu-pen-texture-outside-creation-box-starts", + "pass": true, + "features": 117 + }, + { + "yErrorPixels": 0.03234100341796875, + "xErrorPixels": 0.007296752929676131, + "name": "cpu-extended-pen-region-subpixel-motion", + "pass": true + }, + { + "name": "cpu-real-300-feature-capacity", + "pass": true, + "features": 300 + }, + { + "pass": true, + "rotation": 0.02499544620513916, + "scaleX": 1.025027871131897, + "scaleY": 0.9799908995628357, + "xErrorPixels": 0.0009307861328267109, + "yErrorPixels": 0.0005807876586860772, + "name": "cpu-translation-rotation-independent-xy-scale" + }, + { + "name": "cpu-subpixel-refinement-and-redetection-remain-stationary", + "pass": true + }, + { + "name": "cpu-unrelated-cut-is-not-trusted-motion", + "pass": true + }, + { + "name": "cpu-flat-region-still-refuses-tracking", + "pass": true + }, + { + "generatedFramesAndAnalysisMilliseconds": 51.241667, + "features": 300, + "name": "cpu-1080p-complete-frame-motion", + "pass": true + }, + { + "generatedFramesAndAnalysisMilliseconds": 130.370417, + "features": 300, + "name": "cpu-3840x2160-complete-frame-motion", + "pass": true + }, + { + "name": "metal-pen-texture-outside-creation-box-starts", + "pass": true, + "features": 117 + }, + { + "yErrorPixels": 0.03234100341796875, + "xErrorPixels": 0.007296752929676131, + "name": "metal-extended-pen-region-subpixel-motion", + "pass": true + }, + { + "name": "metal-real-300-feature-capacity", + "pass": true, + "features": 300 + }, + { + "pass": true, + "rotation": 0.02499544620513916, + "scaleX": 1.025027871131897, + "scaleY": 0.9799908995628357, + "xErrorPixels": 0.0009307861328267109, + "yErrorPixels": 0.0005807876586860772, + "name": "metal-translation-rotation-independent-xy-scale" + }, + { + "name": "metal-subpixel-refinement-and-redetection-remain-stationary", + "pass": true + }, + { + "name": "metal-unrelated-cut-is-not-trusted-motion", + "pass": true + }, + { + "name": "metal-flat-region-still-refuses-tracking", + "pass": true + }, + { + "generatedFramesAndAnalysisMilliseconds": 37.962792, + "features": 300, + "name": "metal-1080p-complete-frame-motion", + "pass": true + }, + { + "generatedFramesAndAnalysisMilliseconds": 109.041875, + "features": 300, + "name": "metal-3840x2160-complete-frame-motion", + "pass": true + } + ], + "hostBaseline": { + "version": "1.4.1", + "build": "26", + "sourceWidth": 3840, + "sourceHeight": 2160, + "sourceFPS": 60, + "timelineFPS": 25, + "sourceDurationSeconds": 11.4, + "forwardFromStartTrustedKeys": 65, + "middleReferenceSeconds": 3.68, + "newMiddleKeys": 3, + "displayedFailure": "失去可靠跟踪,保留最后可信帧", + "modalAlert": true, + "originalUserProjectPreserved": true + }, + "realMediaOffline": { + "start": { + "complete": true, + "frames": 285, + "startFrame": 0, + "endFrame": 284, + "last": { + "failure": 0, + "confidence": 0.978393018245697, + "rotation": -0.11834434419870377, + "valid": true, + "frame": 284, + "centerY": 0.9093142151832581, + "flowMatches": 252, + "medianResidualPixels": 0.05460958555340767, + "centerX": 0.4167436957359314, + "scaleY": 1.8007324934005737, + "scaleX": 1.2875596284866333, + "features": 252, + "inliers": 252 + }, + "scope": "Offline decoded gray8 at 1280x720; host confirmation is separate" + }, + "middle-forward": { + "complete": true, + "frames": 193, + "startFrame": 92, + "endFrame": 284, + "last": { + "failure": 0, + "confidence": 0.9728200435638428, + "rotation": -0.03911023586988449, + "valid": true, + "frame": 284, + "centerY": 0.8755143284797668, + "flowMatches": 298, + "medianResidualPixels": 0.06889039278030396, + "centerX": 0.4592028260231018, + "scaleY": 2.144608974456787, + "scaleX": 1.803216576576233, + "features": 298, + "inliers": 298 + }, + "scope": "Offline decoded gray8 at 1280x720; host confirmation is separate" + }, + "middle-backward": { + "complete": true, + "frames": 93, + "startFrame": 92, + "endFrame": 0, + "last": { + "failure": 0, + "confidence": 0.8557574152946472, + "rotation": 0.0420353040099144, + "valid": true, + "frame": 0, + "centerY": 0.5898973941802979, + "flowMatches": 165, + "medianResidualPixels": 0.314788281917572, + "centerX": 0.5102063417434692, + "scaleY": 1.157965064048767, + "scaleX": 1.2286995649337769, + "features": 170, + "inliers": 165 + }, + "scope": "Offline decoded gray8 at 1280x720; host confirmation is separate" + } + }, + "analysisMaximum": [ + 1280, + 720 + ], + "sampling": "Low-pass encoded display luma over the source footprint before decimation, top-first, with pixel aspect correction", + "fitTolerancePixels": 3, + "confidence": "Residual penalty normalized to accepted fit budget; minimum confidence .3, minimum8 inliers,52%consensus and transform/2D-spread guards retained", + "cachePolicy": "First analyzer frame is authoritative; fresh instance, stale cache and changed preview pixels cannot veto the start", + "privacy": "Only aggregate test metadata is committed. User media, exported timeline and decoded frames remain local.", + "limitations": [ + "Offline gray8 decoding differs from host half-float capture; actual FCP acceptance follows formal notarized install.", + "Full Color Finale migration and all-video/occlusion guarantees are not claimed." + ], + "initialNativeTimingFailure": { + "check": "external-activation-main-loop-responsive", + "maximumGapMS": 178.33579168654978, + "context": "Initial run overlapped diagnostic decoding; quiet complete repeat285/285 passed. No test threshold changed." + } +} diff --git a/大鱼调色/Plugin/DYToolHostMethods.inc.h b/大鱼调色/Plugin/DYToolHostMethods.inc.h index 3091433..a640a98 100644 --- a/大鱼调色/Plugin/DYToolHostMethods.inc.h +++ b/大鱼调色/Plugin/DYToolHostMethods.inc.h @@ -15,7 +15,7 @@ - (dy::GrayFrame)toolGrayFrame:(FxImageTile*)tile error:(NSError**)error { @synchronized(_toolCaptureDevices){FxRect b=tile.tilePixelBounds,image=tile.imagePixelBounds;if(b.left!=image.left||b.right!=image.right||b.bottom!=image.bottom||b.top!=image.top)return {}; NSNumber *key=@(tile.deviceRegistryID);NSMutableDictionary *entry=_toolCaptureDevices[key];if(!entry){NSArray *devices=MTLCopyAllDevices();idd=nil;for(idcandidate in devices)if(candidate.registryID==tile.deviceRegistryID)d=candidate;if(d){idlibrary=[d newLibraryWithURL:[[NSBundle bundleForClass:self.class]URLForResource:@"default" withExtension:@"metallib"]error:error];idfunction=[library newFunctionWithName:@"dyToolCapture"];idpipeline=function?[d newComputePipelineStateWithFunction:function error:error]:nil;idqueue=[d newCommandQueue];if(pipeline&&queue){entry=[NSMutableDictionary dictionaryWithDictionary:@{@"device":d,@"pipeline":pipeline,@"queue":queue}];_toolCaptureDevices[key]=entry;}[pipeline release];[queue release];[function release];[library release];}[devices release];if(!entry)return {};} - idtexture=[tile metalTextureForDevice:entry[@"device"]];if(!texture)return {};double aspect=tile.pixelAspect;if(!std::isfinite(aspect)||aspect<=0)return {};aspect=MAX(.01,aspect);double displayHeight=texture.height/aspect,scale=MIN(1.,MIN(3840./texture.width,2160./displayHeight));unsigned width=(unsigned)floor(texture.width*scale),height=(unsigned)floor(displayHeight*scale);if(width<16||height<16||height>2160||width>3840)return {}; + idtexture=[tile metalTextureForDevice:entry[@"device"]];if(!texture)return {};double aspect=tile.pixelAspect;if(!std::isfinite(aspect)||aspect<=0)return {};aspect=MAX(.01,aspect);double displayHeight=texture.height/aspect,scale=MIN(1.,MIN(1280./texture.width,720./displayHeight));unsigned width=(unsigned)floor(texture.width*scale),height=(unsigned)floor(displayHeight*scale);if(width<16||height<16||height>720||width>1280)return {}; idbuffer=[entry[@"device"]newBufferWithLength:width*height*sizeof(float) options:MTLResourceStorageModeShared];if(!buffer)return {};vector_uint3 info={width,height,(unsigned)(tile.imageOrigin==kFxImageOrigin_BOTTOM_LEFT)};idcommands=[entry[@"queue"]commandBuffer];idencoder=[commands computeCommandEncoder];[encoder setComputePipelineState:entry[@"pipeline"]];[encoder setTexture:texture atIndex:0];[encoder setBuffer:buffer offset:0 atIndex:0];[encoder setBytes:&info length:sizeof(info) atIndex:1];[encoder dispatchThreads:MTLSizeMake(width,height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[encoder endEncoding];[commands commit];[commands waitUntilCompleted];dy::GrayFrame frame;if(commands.status==MTLCommandBufferStatusCompleted){frame={int(width),int(height),std::vector(width*height)};memcpy(frame.pixels.data(),buffer.contents,width*height*sizeof(float));}[buffer release];return frame; } } diff --git a/大鱼调色/Plugin/DYToolTrackingDiagnostics.inc.h b/大鱼调色/Plugin/DYToolTrackingDiagnostics.inc.h index 7f9c860..eaac755 100644 --- a/大鱼调色/Plugin/DYToolTrackingDiagnostics.inc.h +++ b/大鱼调色/Plugin/DYToolTrackingDiagnostics.inc.h @@ -27,5 +27,11 @@ DYWriteTools(base,doc,kCMTimeZero);capture(0);request(1);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; // Deliberately different preview pixels must not veto an authoritative analysis seed. for(int i=0;i<3&&callbacks;i++){setFrame(i+2);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}[plugin cleanupAnalysis:nil];drain();tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];run.record(@"analysis-seed-does-not-require-preview-pixel-equality",callbacks&&[tracked[@"keys"]count]==3); + { + const NSUInteger w=3840,h=2160;DYDiagnosticTile *fine=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease];Pixels pixels(w*h*4); + for(NSUInteger y=0;y { @public id _base;CMTime _time;FxAnalysisState _state;int _forwardStarts,_backwardStarts; @@ -23,6 +24,7 @@ - (BOOL)setupAnalysisForTimeRange:(CMTimeRange)range frameDuration:(CMTime)duration error:(NSError**)error; - (BOOL)analyzeFrame:(FxImageTile*)frame atTime:(CMTime)time error:(NSError**)error; - (BOOL)cleanupAnalysis:(NSError**)error; +- (dy::GrayFrame)toolGrayFrame:(FxImageTile*)tile error:(NSError**)error; @end @interface DYToolCanvasProbe : DYToolTrackingProbe @end diff --git a/大鱼调色/Plugin/DYTracking.metal b/大鱼调色/Plugin/DYTracking.metal index ec515f4..dc6484a 100644 --- a/大鱼调色/Plugin/DYTracking.metal +++ b/大鱼调色/Plugin/DYTracking.metal @@ -50,8 +50,11 @@ kernel void dyTrackFlow(device const float*prev[[buffer(0)]],device const float* if(lane==0)results[idx]=float4(q,error,ok?1.f:0.f); } -// Full host frame -> top-first display luma. Analysis and reference use the -// same sampler, alpha convention and transfer; no 320x180 inspector preview. +// Full host frame -> top-first display luma. Low-pass the source footprint +// before decimation so 4K fabric detail cannot alias into inconsistent motion. +// This analysis-only image never changes the full-resolution color render. kernel void dyToolCapture(texture2d source [[texture(0)]],device float* pixels [[buffer(0)]],constant uint3& info [[buffer(1)]],uint2 pos [[thread_position_in_grid]]){ - if(pos.x>=info.x||pos.y>=info.y)return;constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);float2 uv=(float2(pos)+.5f)/float2(info.xy);if(info.z)uv.y=1-uv.y;float4 sample=source.sample(f,uv);float3 linear=sample.a>0?sample.rgb/sample.a:float3(0);float3 encoded=select(1.055f*pow(max(linear,float3(0)),float3(1.f/2.4f))-.055f,linear*12.92f,linear<=.0031308f);pixels[pos.y*info.x+pos.x]=dot(clamp(encoded,0.f,1.f),float3(.2126f,.7152f,.0722f)); + if(pos.x>=info.x||pos.y>=info.y)return;constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);uint2 taps=clamp(uint2(ceil(float2(source.get_width(),source.get_height())/float2(info.xy))),uint2(1),uint2(8));float sum=0; + for(uint y=0;y0?sample.rgb/sample.a:float3(0);float3 encoded=select(1.055f*pow(max(linear,float3(0)),float3(1.f/2.4f))-.055f,linear*12.92f,linear<=.0031308f);sum+=dot(clamp(encoded,0.f,1.f),float3(.2126f,.7152f,.0722f));} + pixels[pos.y*info.x+pos.x]=sum/float(taps.x*taps.y); }