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 ?
Asked
Active
Viewed 573 times
4

user3128673
- 663
- 1
- 5
- 6
1 Answers
4
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)
}
}

Rhythmic Fistman
- 34,352
- 5
- 87
- 159