AVAssetReader/AVAssetWriter preview of current frame
I'm using AVAssetReader/AVAssetWriter
to convert my video on iOS. My question is: what's the most efficient way to show preview of current frame with real time conversion. I was thinking about converting CMSampleBufferRef
to UIImage, then applying into UIImageView. It there any better way ?
I think AVSampleBufferDisplayLayer
is what you're looking for.
It's a CALayer
subclass that can display CMSampleBuffer
s and I imagine it's much faster than a trek through UIImage
and UIImageView
.
Here is a simple AVSampleBufferDisplayLayer
-backed UIView
implementation (in swift):
class SampleBufferView: UIView {
override class func layerClass() -> AnyClass {
return AVSampleBufferDisplayLayer.self
}
func enqueueSampleBuffer(sampleBuffer: CMSampleBuffer!) {
let displayLayer = self.layer as! AVSampleBufferDisplayLayer
displayLayer.enqueueSampleBuffer(sampleBuffer)
}
}
链接地址: http://www.djcxy.com/p/72050.html