Skip to content

Unable to get new video frames #3

Open
@jessie-young

Description

@jessie-young

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.
    }
}



Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions