카메라를 열고 비디오를 미리 볼 수있는 코드를 작성했습니다. 카메라 성공적으로Swift에서 AVCaptureSession의 출력을 서버에 보내려면
import UIKit
import AVFoundation
class ViewController: UIViewController {
let captureSession = AVCaptureSession()
var previewLayer : AVCaptureVideoPreviewLayer?
// If we find a device we'll store it here for later use
var captureDevice : AVCaptureDevice?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
captureSession.sessionPreset = AVCaptureSessionPresetHigh
let devices = AVCaptureDevice.devices()
// Loop through all the capture devices on this phone
for device in devices {
// Make sure this particular device supports video
if (device.hasMediaType(AVMediaTypeVideo)) {
// Finally check the position and confirm we've got the back camera
if(device.position == AVCaptureDevicePosition.Back) {
captureDevice = device as? AVCaptureDevice
if captureDevice != nil {
println("Capture device found")
beginSession()
}
}
}
}
}
func beginSession() {
var err : NSError? = nil
captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &err))
if err != nil {
println("error: \(err?.localizedDescription)")
}
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
self.view.layer.addSublayer(previewLayer)
previewLayer?.frame = self.view.layer.frame
captureSession.startRunning()
}
}
이 열려 나는 장면을 미리 볼 수 있습니다 : 지금 이상적으로 H.264 여기
로 인코딩 서버로 보낼 수있는 출력에서 프레임을 캡처 할 내가있어 무엇 .
나는 출력을 얻는 것처럼 보이는이 Objective C 코드를 발견했지만이를 신속하게 변환하는 방법을 모른다. AVCaptureVideoDataOutput, AVAssetWriter, AVAssetWriterInput 및 AVAssetWriterInputPixelBufferAdaptor를 사용하여 프레임을 H.264로 인코딩 된 동영상 파일에 기록합니다.
Can use AVCaptureVideoDataOutput and AVCaptureMovieFileOutput at the same time?
누군가가 그것을 변환 할 또는 내 현재 코드에서 프레임을 활용하는 방법에 관해서는 저에게 조언 해 줄 수 있습니까?
이러한 종류의 문서는 신속하게 제공되지 않습니다. 상당히 실망 스럽습니다. –
해결책을 찾았습니까? –
[AVCaptureVideoDataOutput과 AVCaptureMovieFileOutput을 동시에 사용할 수 있습니까?] (http://stackoverflow.com/questions/4944083/can-use-avcapturevideodataoutput-and-avcapturemoviefileoutput-at-the-same-time)에서 코드를 변환하려고하십니까?) 신속하게? –