我来自CVPixelBufferRef
AVAsset
。我正在尝试对其应用CIFilter
。我使用这些行:
CVPixelBufferRef pixelBuffer = ...
CVPixelBufferRef newPixelBuffer = // empty pixel buffer to fill
CIContex *context = // CIContext created from EAGLContext
CGAffineTransform preferredTransform = // AVAsset track preferred transform
CIImage *phase1 = [CIImage imageWithCVPixelBuffer:pixelBuffer];
CIImage *phase2 = [phase1 imageByApplyingTransform:preferredTransform];
CIImage *phase3 = [self applyFiltersToImage:phase2];
[context render:phase3 toCVPixelBuffer:newPixelBuffer bounds:phase3.extent colorSpace:CGColorSpaceCreateDeviceRGB()];
不幸的是,我得到的结果方向不正确。例如,以纵向模式拍摄的视频是颠倒的。我想问题是从AVAsset
到CoreImage
坐标系统(在XCode中显示 phase2 的预览也会显示错误的结果)。如何解决?
答案 0 :(得分:3)
我通过这样解决了它,它应该正确地将所有东西定向到坐标空间
var preferredTransform = inst.preferredTransform
preferredTransform.b *= -1
preferredTransform.c *= -1
var outputImage = CIImage(cvPixelBuffer: videoFrameBuffer)
.applying(preferredTransform)
outputImage = outputImage.applying(CGAffineTransform(translationX: -outputImage.extent.origin.x, y: -outputImage.extent.origin.y))