我正在尝试将滤镜应用于在 iOS 上使用 AVFoundation 创建的视频合成(滤镜可以是模糊、像素化、棕褐色等)。我需要实时应用效果并能够将复合视频渲染到磁盘,但我很高兴从其中之一开始。
不幸的是,我似乎无法弄清楚这一点。这是我能做的:
- 我可以向正在播放电影的 UIView 添加一个动画层,但我不清楚是否可以通过这种方式处理传入的视频图像。
- 我可以将 CIFilter 数组添加到 AVPlayerLayer,但事实证明这些在 iOS 中被忽略(它仅适用于 Mac OS X)。
- 我可以将 AVVideoCompositionCoreAnimationTool 添加到 AVVideoCompopsition,但我不确定这是否会完成视频处理(而不是动画),并且它会崩溃并显示一条关于不适合实时播放的消息。我相信这是渲染到磁盘时渲染动画的解决方案。
其他应用程序也这样做(我认为),所以我认为我错过了一些明显的东西。
注意:我研究过 GPUImage 并且很想使用它,但它不适用于电影,尤其是带有音频的电影。参见示例:
- AVMutableComposition 上运行时的 GPUImage 过滤器 https://stackoverflow.com/questions/18349021/gpuimage-filters-in-runtime-on-avmutablecomposition
- https://github.com/BradLarson/GPUImage/issues/1339 https://github.com/BradLarson/GPUImage/issues/1339
你可以使用AV视频合成 https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVVideoCompositing_Protocol/Reference/Reference.html and AVA同步视频合成请求 https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVAsynchronousVideoCompositionRequest_Class/Reference/Reference.html#//apple_ref/doc/c_ref/AVAsynchronousVideoCompositionRequest实现自定义合成器的协议。
CVPixelBufferRef pixelBuffer = [AVAsynchronousVideoCompositionRequest sourceFrameByTrackID:trackID];
CIImage *theImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
CIImage *motionBlurredImage = [[CIFilter *filterWithName:@"CIMotionBlur" keysAndValues:@"inputImage", theImage, nil] valueForKey:kCIOutputImageKey];
CIContext *someCIContext = [CIContext contextWithEAGLContext:eaglContext];
[someCIContext render:motionBlurredImage toCVPixelBuffer:outputBuffer];
然后使用 OpenGL 渲染像素缓冲区,如中所述苹果的文档 https://developer.apple.com/library/ios/documentation/3ddrawing/conceptual/opengles_programmingguide/WorkingwithEAGLContexts/WorkingwithEAGLContexts.html。这将允许您实现任意数量的您想要的转换或过滤器。然后,您可以设置 AVAssetExportSession.videoCompostion,然后就可以将合成视频导出到磁盘。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)