Skip to content

Instantly share code, notes, and snippets.

@hk0i
Created April 6, 2017 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hk0i/d832679956945561c56927adbfe1f3a2 to your computer and use it in GitHub Desktop.
Save hk0i/d832679956945561c56927adbfe1f3a2 to your computer and use it in GitHub Desktop.
// MARK: - AVCaptureVideoDataOutputSampleBufferDelegate extension {{{
extension CtsVideoCallView: AVCaptureVideoDataOutputSampleBufferDelegate {
func captureOutput(_ captureOutput: AVCaptureOutput!,
didOutputSampleBuffer sampleBuffer: CMSampleBuffer!,
from: AVCaptureConnection!) {
// get image size for preview and resize preview view accordingly
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault,
sampleBuffer, kCMAttachmentMode_ShouldPropagate) as! Dictionary
let ciImage = CIImage(cvPixelBuffer: imageBuffer, options: attachments)
let height = ciImage.cgImage.height
let width = ciImage.cgImage.width
let localVideoSize = CGSize(width: width, height: height)
self.localVideoView.frame.size = localVideoSize
}
}
// }}} AVCaptureVideoDataOutputSampleBufferDelegate extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment