Awalz / SwiftyCam

A Snapchat Inspired iOS Camera Framework written in Swift
BSD 2-Clause "Simplified" License
2.08k stars 327 forks source link

videoCodecType selection doesn't stick after switching the camera with switchCamera #235

Open steveellis opened 3 years ago

steveellis commented 3 years ago

I set the videoCodecType to .h264 in viewDidLoad the video records in h264. But If I call switchCamera then the video records as HVEC.

From what I can tell it's because the codec selection doesn't persist after the session inputs change in switchCamera and defaults back to HVEC. I thought I could just set videoCodecType either before or after switching the camera via switchCamera, but that appears to have no effect. After switching the codec is always HVEC.

It looks like configureVideoOutput (where videoCodecType comes into play) is called only in viewDidLoad, maybe it should be called in switchCamera too or at least some of its logic needs to be present in switching the camera perhaps.

Seems like a workaround for now is to persist the current camera state (front or back) and then reload the view entirely with the new state. But thought I would let you know what I'm seeing. Maybe I'm missing a different way to make it work without reloading the view. Thanks!

steveellis commented 3 years ago

Seems like my issue may be a duplicate of this https://github.com/Awalz/SwiftyCam/issues/208 or at least @ShaikBaji1506 is having the same problem of the codec not being carried over when switching cams.

I'm able to solve this by reloading the view controller entirely when switching camera and setting the desired camera using the defaultCamera property, and then calling super.viewDidLoad which applies the codec I select (.h264) to the session, but I do think it's a bug if switchCamera always ends up with HVEC so I'll leave the issue open in the hopes that it can be fixed.