【问题标题】:Need hints for using iPhone SDK's AVMutableVideoComposition需要使用 iPhone SDK 的 AVMutableVideoComposition 的提示
【发布时间】:2011-03-24 23:58:24
【问题描述】:

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

谢谢, 乔恩

【问题讨论】:

    标签: iphone avfoundation


    【解决方案1】:

    不确定是否有帮助。

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

    【讨论】:

    • 谢谢。这让我更接近,但仍然不完全在那里。什么是资产“组成”?如果我使用:AVMutableComposition *composition = [AVMutableComposition composition];,那么编译器会抱怨 videoComposition 不包含任何指令。我不知道要添加什么说明。对不起,我很厚。
    • 你检查过 WWDC 2010 的 AVEditDemo 项目吗?你可以在苹果的开发者页面上找到它,或者从这里下载它:rghost.net/2649255 在那个项目中你可以找到一个使用带有导出功能的 AVVideoCompositionCoreAnimationTool 的例子。希望对您有所帮助。
    猜你喜欢
    • 2011-07-24
    • 1970-01-01
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多