3

AVFoundation フレームワークは、AVMutableVideoComposition クラス (AVVideoComposition の変更可能なバリアント) を提供します。CoreAnimations をこのクラスのインスタンスに直接レンダリングしてビデオを作成できるように見えますが、コンポジションをファイルに保存する方法や、それを操作する方法がまったくわかりません。UIViewController から呼び出された次のコードは、コンポジションとアニメーションを作成するために機能しているように見えますが、コンポジションを操作する方法に困惑しています。どんな助けや指導も大歓迎です。

static AVMutableVideoComposition *videoComposition = nil;
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag {
 //Do something with videoComposition here... how to save it to a file?
 NSLog(@"videoComposition: %@", videoComposition);
 [videoComposition release]; videoComposition = nil;
}

- (IBAction)createVideoComposition:(id)sender {
 AVVideoCompositionCoreAnimationTool *videoCompositionCoreAnimationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:self.view.layer inLayer:self.view.layer];
 videoComposition = [[AVMutableVideoComposition videoComposition] retain];
 [videoComposition setRenderSize:CGSizeMake(320.0, 480.0)];
 [videoComposition setRenderScale:1.0];
 [videoComposition setFrameDuration:CMTimeMake(1, 10)];
 [videoComposition setAnimationTool:videoCompositionCoreAnimationTool];
 //add a basic animation to shake the controller's view
 CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
 shakeAnimation.delegate = self;
 shakeAnimation.removedOnCompletion = YES;
 shakeAnimation.duration = 0.5;
 CGMutablePathRef path = CGPathCreateMutable();
 CGFloat midX = self.view.center.x;
 CGFloat midY = self.view.center.y;
 CGPathMoveToPoint(path, nil, midX, midY);
 CGPathAddLineToPoint(path, nil, midX + 10.0, midY);
 CGPathAddLineToPoint(path, nil, midX - 20.0, midY);
 CGPathAddLineToPoint(path, nil, midX + 15.0, midY);
 CGPathAddLineToPoint(path, nil, midX - 5.0, midY);
 CGPathAddLineToPoint(path, nil, midX, midY);
 shakeAnimation.path = path;
 CFRelease(path);
 [self.view.layer addAnimation:shakeAnimation forKey:@"shakeAnimation"];
}

ありがとう、ジョン

4

1 に答える 1

2

それが役立つかどうかわからない。

    AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality];
    session.videoComposition = videoComposition;
    session.outputURL = outputURL;
    session.outputFileType = AVFileTypeQuickTimeMovie;
    [session exportAsynchronouslyWithCompletionHandler:
         ^(void )
{
        NSLog(@"TADA!")
    }];
于 2010-09-13T06:38:41.610 に答える