Can the iPhone4 record from both front and rear-facing camera at the same time?

假装没事ソ 提交于 2019-11-28 11:02:01

It's something the API does allow for. I tried three approaches on an iPhone 4 running the latest iOS, 4.2.1.

Firstly, I tried using a single capture session with both video devices attached as inputs. Attaching the second device produces an exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* Multiple audio/video AVCaptureInputs are not currently supported.'

Secondly, I tried setting up two different sessions, each with only one camera and starting them at the same time. This caused the first session to report frames for about a second, but as soon as the second starts the first stops of its own volition. The order in which you send 'startRunning' dictates which of the sessions ultimately manages to force the other out.

Finally, I tried a simple ping pong approach. So I create two sessions, start the first and as soon as it reports a frame, stop it and start the second. Then stop the second and start the first, ad infinitum. Sadly the latency between requesting a session start and receiving the first frame left me with about one frame every two seconds.

Of course it's possible I erred in my code, but I'm inclined to say that it's not possible on the current hardware or OS. I shall hook the AVCaptureSession notifications to see if I'm given an explicit reason why one stops and update this post.

Additions: my program receives only the AVCaptureSessionDidStartRunningNotification notifications, one from each capture session. The one that halts doesn't report an error, interruption or other stoppage. I am also unable to find an issue with my code, such as an object or dispatch queue reuse, that might conceivably cause this problem.

It appears to be possible to record from multiple video inputs using the AVFoundation API. According to the documentation, multiple AVCaptureDevice inputs can be used in an AVCaptureSession. In an iPhone 4 this means that a session could have both AVCaptureDevices for both cameras. In practice, it might not be feasible. I haven't tried it so I can't tell with certainty.

I don't think the standard UIImagePickerController can be used to record from both at the same time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!