2010-08-03 1 views
3

AVFoundation 프레임 워크는 AVMutableVideoComposition 클래스 (AVVideoComposition의 변종)를 제공합니다. 비디오를 만들기 위해이 클래스의 인스턴스에 CoreAnimations를 직접 렌더링 할 수있는 것처럼 보이지만 파일에 컴포지션을 저장하는 방법이나 전혀 작업하는 방법을 알지 못합니다. UIViewController에서 호출 된 다음 코드는 컴포지션 및 애니메이션을 만드는 데 사용되지만 컴포지션 작업 방법에 관해서는 잘 모르겠습니다. 어떤 도움이나지도도 크게 감사드립니다.iPhone SDK의 AVMutableVideoComposition 사용에 대한 힌트가 필요합니다.

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"]; 
} 

감사합니다, 존

답변

2

도움이된다면 확실하지.

AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality]; 
    session.videoComposition = videoComposition; 
    session.outputURL = outputURL; 
    session.outputFileType = AVFileTypeQuickTimeMovie; 
    [session exportAsynchronouslyWithCompletionHandler: 
     ^(void) 
{ 
     NSLog(@"TADA!") 
    }]; 
+0

감사합니다. 이것은 나를 더 가깝게하고 있지만 아직도 거기에 있지는 않습니다. 자산 "구성"은 무엇입니까? 내가 사용하는 경우 : 'AVMutableComposition * composition = [AVMutableComposition composition]; ' 그러면 컴파일러는 videoComposition에 명령어가 없다는 것에 불평합니다. 추가 할 지침을 모르겠습니다. 두려워서 미안해. – Jon

+1

WWDC 2010에서 AVEditDemo 프로젝트를 확인 했습니까? 당신은 애플의 개발자 페이지에서 그것을 찾거나 여기에서 다운로드 할 수 있습니다 : http://rghost.net/2649255 그 프로젝트에서 당신은 수출 기능을 가진 AVVideoCompositionCoreAnimationTool을 사용하는 예제를 발견 할 수 있습니다. 희망이 도움이됩니다. – Steve