私たちは結果を出すことなくかなりの時間を費やして、ここでそれを聞くことにしました。Swift 3でAVCaptureVideoDataOutputを使用してビデオを録画する
AVCaptureVideoDataOutput
を使用して、カメラのライブビデオのピクセルデータを取得し、captureOutput
機能で使用しています。しかし、我々はまた、そのデータを使用してビデオを記録したい。さらに、このビデオ録画が、AVCaptureMovieFileOutput
で作られた録画されたビデオほど圧縮されているのだろうかと思う。
AVCaptureMovieFileOutput
を使用して問題なく録音したことをお知らせします。しかし、AVCaptureMovieFileOutput
とAVCaptureVideoDataOutput
は同時に動作しません。
下記のcaptureOutput
機能があります。
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
CVPixelBufferLockBaseAddress(imageBuffer, CVPixelBufferLockFlags(rawValue: 0))
let baseAddress = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0)
let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer)
videoWidth = CVPixelBufferGetWidth(imageBuffer)
videoHeight = CVPixelBufferGetHeight(imageBuffer)
let colorSpace = CGColorSpaceCreateDeviceRGB()
var bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
let context = CGContext(data: baseAddress, width: videoWidth, height: videoHeight, bitsPerComponent: 8, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)
let imageRef = context!.makeImage()
CVPixelBufferUnlockBaseAddress(imageBuffer, CVPixelBufferLockFlags(rawValue: 0))
let data = imageRef!.dataProvider!.data as! NSData
let pixels = data.bytes.assumingMemoryBound(to: UInt8.self)
/* Because what we are doing with pixel data irrelevant to the question we omitted the rest of the code to make it simple */
}