Tôi đã quản lý để viết một số mã mở máy ảnh và xem trước video. bây giờ tôi muốn nắm bắt được khung hình từ đầu ra để gửi đến một máy chủ lý tưởng mã hóa như H.264Nhận đầu ra từ AVCaptureSession trong Swift để gửi đến máy chủ
Đây là những gì tôi đã có:
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()
}
}
mở này camera thành công và tôi có thể xem trước các cảnh quay .
Tôi đã tìm thấy mã C Mục tiêu này có vẻ như nó nhận được kết quả đầu ra nhưng tôi không biết cách chuyển đổi nó thành nhanh. Nó đang sử dụng AVCaptureVideoDataOutput, AVAssetWriter, AVAssetWriterInput và AVAssetWriterInputPixelBufferAdaptor để ghi khung hình ra tệp phim được mã hóa H.264.
Can use AVCaptureVideoDataOutput and AVCaptureMovieFileOutput at the same time?
Ai đó có thể giúp chuyển đổi nó hoặc cho tôi gợi ý như thế nào để có được những khung hình ra khỏi mã hiện tại của tôi?
Tài liệu về những thứ này thiếu nhanh chóng. Nó khá bực bội. –
Bạn đã tìm thấy giải pháp chưa? –
là bạn đang cố chuyển đổi mã từ [Có thể sử dụng AVCaptureVideoDataOutput và AVCaptureMovieFileOutput cùng một lúc không?] (Http://stackoverflow.com/questions/4944083/can-use-avcapturevideodataoutput-and-avcapturemoviefileoutput-at-the-same-time) để nhanh chóng? –