この質問が出されてからしばらく経ちましたが、どこを見ても、記録中にリアルタイムでデータをサンプリングすることで同様のことを思いつきました(30fpsで記録されたビデオのタイマーで1/30秒)および保存それを配列にします。次に、後処理で、配列内の各データ要素のループで複数の CALayer を作成し、各レイヤーにそのデータの視覚化を描画します。
各レイヤーには CAAnimation があり、 beginTime属性 (単純に 1/30 秒) を持つ正しいメディア タイムラインで不透明にフェードインします。配列インデックスを掛けます。これは非常に短い時間であるため、レイヤーが直前のレイヤーの上にすぐに表示されます。レイヤーの背景が不透明な場合、前のレイヤーでレンダリングされた針が見えにくくなるため、元のビデオ キャプチャとかなり同期して針がアニメートされているように見えます。タイミングを少し調整する必要があるかもしれませんが、1 フレームしかずれていません。
/******** this has not been compiled but you should get the idea ************
// Before starting the AVAssetExportSession session and after the AVMutableComposition routine
CALayer* speedoBackground = [[CALayer alloc] init]; // background layer for needle layers
[speedoBackground setFrame:CGRectMake(x,y,width,height)]; // size and location
[speedoBackground setBackgroundColor:[[UIColor grayColor] CGColor]];
[speedoBackground setOpacity:0.5] // partially see through on video
// loop through the data
for (int index = 0; index < [dataArray count]; index++) {
CALayer* speedoNeedle = [[CALayer alloc] init]; // layer for needle drawing
[speedoNeedle setFrame:CGRectMake(x,y,width,height)]; // size and location
[speedoNeedle setBackgroundColor:[[UIColor redColor] CGColor]];
[speedoNeedle setOpacity:1.0]; // probably not needed
// your needle drawing routine for each data point ... e.g.
[self drawNeedleOnLayer:speedoNeedle angle:[self calculateNeedleAngle[dataArray objectAtIndex:index]]];
CABasicAnimation *needleAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
needleAnimation.fromValue = [NSNumber numberWithFloat:(float)0.0];
needleAnimation.toValue = [NSNumber numberWithFloat:(float)1.0]; // fade in
needleAnimation.additive = NO;
needleAnimation.removedOnCompletion = NO; // it obscures previous layers
needleAnimation.beginTime = index*animationDuration;
needleAnimation.duration = animationDuration -.03; // it will not animate at this speed but layer will appear immediately over the previous layer at the correct media time
needleAnimation.fillMode = kCAFillModeBoth;
[speedoNeedle addAnimation:needleAnimation forKey:nil];
[speedoBackground addSublayer:needleOverlay];
}
[parentLayer addSublayer:speedoBackground];
.
.
.
// when the AVAssetExportSession has finished, make sure you clear all the layers
parentLayer.sublayers = nil;
プロセッサとメモリを大量に消費するため、長いビデオや複雑な描画には適していません。もっとエレガントな方法があると確信していますが、これは機能し、これが役立つことを願っています.