AVFoundation
有没有办法在iOS中获得方形视频输出?
我使用 OpenGL 来处理CMSampleBuffer
视频的每一帧()。每一帧
都是旋转的,所以我需要裁剪和旋转CMSampleBuffer
。但我不知道该怎么做,所以我相信有一种方法可以通过videoSettings
在AVCaptureVideoDataOutput
.
我用谷歌搜索,谷歌搜索并搜索它,但一无所获。swift中的代码示例会很棒。
更新:
我在 Swift 中的完整最终解决方案:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
captureSession = AVCaptureSession()
captureSession!.sessionPreset = AVCaptureSessionPreset640x480
let backCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
var error: NSError?
var input: AVCaptureDeviceInput!
do {
input = try AVCaptureDeviceInput(device: backCamera)
} catch let error1 as NSError {
error = error1
input = nil
}
if error == nil && captureSession!.canAddInput(input) {
captureSession!.addInput(input)
stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput!.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG, kCVPixelBufferPixelFormatTypeKey: Int(kCVPixelFormatType_32BGRA)]
if captureSession!.canAddOutput(stillImageOutput) {
captureSession!.addOutput(stillImageOutput)
}
}
videoOutput = AVCaptureVideoDataOutput()
videoOutput!.videoSettings = [kCVPixelBufferPixelFormatTypeKey: Int(kCVPixelFormatType_32BGRA), AVVideoWidthKey : 100, AVVideoHeightKey: 100]
videoOutput!.setSampleBufferDelegate(self, queue: dispatch_queue_create("sample buffer delegate", DISPATCH_QUEUE_SERIAL))
if captureSession!.canAddOutput(self.videoOutput) {
captureSession!.addOutput(self.videoOutput)
}
videoOutput!.connectionWithMediaType(AVMediaTypeVideo).videoOrientation = AVCaptureVideoOrientation.PortraitUpsideDown
videoOutput!.connectionWithMediaType(AVMediaTypeVideo).videoMirrored = true
captureSession!.startRunning();
}
它对我来说是完美的镜像和旋转视频输出!但它不是裁剪!