需要有关使用iPhone SDK的AVMutableVideoComposition的提示 [英] Need hints for using iPhone SDK's AVMutableVideoComposition

查看:141
本文介绍了需要有关使用iPhone SDK的AVMutableVideoComposition的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AVFoundation框架提供AVMutableVideoComposition类(AVVideoComposition的可变变体)。看起来您可以直接将CoreAnimations渲染到此类的实例来创建视频,但我不知道如何将组合保存到文件或者根本不知道如何使用它。从UIViewController调用的以下代码似乎可以用于创建合成和动画,但是,好吧,我很难理解如何使用合成。非常感谢任何帮助或指导。

The AVFoundation framework provides the AVMutableVideoComposition class (the mutable variant of AVVideoComposition). It looks like you can render CoreAnimations directly to an instance of this class to create a video but I don't know how to save the composition to a file or how to work with it at all, really. The following code called from a UIViewController appears to work to create the composition and the animation but, then, well, I'm stumped as to how to work with the composition. Any help or guidance is greatly appreciated.

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

谢谢,
Jon

Thanks, Jon

推荐答案

不确定是否有帮助。

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

这篇关于需要有关使用iPhone SDK的AVMutableVideoComposition的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆