RxAVFoundation icon indicating copy to clipboard operation
RxAVFoundation copied to clipboard

Unable to get new video frames

Open jessie-young opened this issue 4 years ago • 1 comments

I pulled the RxAVFoundation dependency into my Swift project and attempted to use the videoCaptureOutput method to print a new log statement whenever we get a new captureOutput. However, it seems like we never get any .next events. Here's my ViewController.swift

//
//  ViewController.swift
//  RxTest
//
//  Created by Jessie Young on 6/28/21.
//

import UIKit
import AVFoundation
import RxSwift

class ViewController: UIViewController {

    // capture session
    private let session = AVCaptureSession()
    private var videoDevice: AVCaptureDevice!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.videoDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)
    
        session
            .rx
            .configure(captureDevice: videoDevice)
    
        let disposeBag = DisposeBag()
        
        let videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString) : NSNumber(value: kCVPixelFormatType_32BGRA)] as [String : Any]
        
        session
            .rx
            .videoCaptureOutput(settings: videoSettings)
            .observeOn(MainScheduler.instance)
            .subscribe { [unowned self] (event) in
                switch event {
                    case .next(let captureOutput):
                        print("got a frame")
                    case .error(let error):
                        print("error: %@", "\(error)")
                    case .completed:
                        break // never happens
                }
            }
            .disposed(by: disposeBag)

        
        session
            .rx
            .startRunning()

        
        // Do any additional setup after loading the view.
    }
}



jessie-young avatar Jun 28 '21 22:06 jessie-young

@maxvol any ideas as to why this sample code is not working?

jessie-young avatar Jun 29 '21 00:06 jessie-young