Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
108.54k stars 10.45k forks source link

Request: multiple cameras at once #4451

Open rektide opened 9 months ago

rektide commented 9 months ago

Is your feature request related to a problem? Please describe. My phone has 4 different cameras. I'd love to be able to use >1 at a time. It'd be nice to be able to capture, for example, myself, and the thing I'm looking at the same time. Another use case, I've started making videos of some of my bicycle rides. It'd be great if I could have both a wide angle shot and a tight shot rolling at once, from the wide angle and zoom back cameras.

Describe the solution you'd like Ideally I could run multiple copies of scrcpy with different --camera-id's specified and get multiple different cameras streaming at once into different windows.

Describe alternatives you've considered One alternative that likely would be acceptable for me is to stream multiple cameras as multiple different windows via a single instance of scrcpy. A user might be able to specify multiple different streaming things, separated by -- or some such. This is not-optimal for me, as I can't turn cameras on and off on the fly; both cameras need to be configured ahead of time and stay on. But it would be better than what I have now.

One thought I had but wasn't able to follow up on is maybe it's possible to create multiple different multiple serial links to my phone and that maybe that might help. I don't know adb very well nor it's technical limitations, but I poked around for a bit & I don't think I got anywhere in terms of setting up multiple connections. One thing I tried here was seeing if I could use -P port to maybe launch multiple adb servers at once and have them each pair. I was able to pair from each server, but they both listed the same serial id, and I'm not sure if this was helping at all. I couldn't find any way to point scrcpy at different adb ports, and don't know if that makes sense/is a thing.

Nightmare scary mode (to me)_might be trying to make one scrcpy somehow blit multiple cameras or screens together in some way. That seems like it would be hard to configure well.

Additional context I am using adb-over-wifi serial to talk to a Samsung S22, with Android 13. Right now I'm on a Windows 11 box. (I should try again once I get this beefy desktop machine's dual boot running again!)

I'm trying to run scrcpy twice, as so:

$ scrcpy -s adb-R5CRC3MLEFK-Po0SPe._adb-tls-connect._tcp. --no-audio --video-bit-rate=2M --video-source=camera --camera-size=960x720 --camera-id=0 --window-title=phonecam-back
$ scrcpy -s adb-R5CRC3MLEFK-Po0SPe._adb-tls-connect._tcp. --no-audio --video-bit-rate=2M --video-source=camera --camera-size=960x720 --camera-id=1 --window-title=phonecam-front

When I start the second scrcpy, the first instance dies as so, closing the window, and then the new scrcpy window starts up with the desired video camera (as normal, without trouble):

[server] WARN: Camera disconnected
[server] WARN: Camera capture failed: frame 121
[server] WARN: Camera capture failed: frame 122
[server] WARN: Camera capture failed: frame 123
[server] WARN: Camera capture failed: frame 124
[server] WARN: Camera capture failed: frame 125
[server] WARN: Camera capture failed: frame 120
WARN: Device disconnected

One additional bit of context, I can run either the front or back camera while also capturing the screen. Ex of that invocation:

$ scrcpy -s adb-R5CRC3MLEFK-Po0SPe._adb-tls-connect._tcp.  --no-audio --video-bit-rate=3M --window-title=phone 

I've also played with various settings some, to no effect. I've tried running one stream with --audio-source=mic and one with --audio-source=output. I've tried with one --no-audio and the other a source. I've tried using some other resolutions (640x480). I've tried --video-codec=h264 and each of the 4 different --video-encoder options shown for h264 in --list-encoders (full list: OMX.google.h264.encoder c2.qti.avc.encoder OMX.qcom.video.encoder.avc c2.android.avc.encoder). One thing that I thought was promising was to specify a --port=28183:28199 non-default port for the second camera, but that didn't help. So far none of these have made a difference that I've seen.

rom1v commented 9 months ago

When I start the second scrcpy, the first instance dies as so, closing the window, and then the new scrcpy window starts up with the desired video camera (as normal, without trouble)

Yes, it is the (physical, I guess) limitation on the Android device. As soon as we start a new camera capture, ne old one get disconnected.

There's probably nothing scrcpy can do.

yume-chan commented 9 months ago

https://developer.android.com/reference/android/hardware/camera2/CameraManager#getConcurrentCameraIds()

The devices in these combinations can be concurrently configured by the same client camera application. Using these camera devices concurrently by two different applications is not guaranteed to be supported, however.

For concurrent operation, in chronological order :

  1. Maybe one Scrcpy instance can open multiple cameras. This requires a huge refactoring to allow one Scrcpy server to accept multiple client connections.
  2. Opening a new camera requires closing and re-opening other already opened cameras.
  3. Depends on the device, some camera combinations might not work.
TheBug233 commented 6 months ago

My phone natively supports simultaneous shooting with multiple cameras (two rear cameras and one front camera). Additionally, in the DSU Loader system, it's possible to mirror two cameras simultaneously in Scrcpy. However, it's unfortunate that DSU Loader cannot recognize the wide-angle camera on my phone.

So, is this a software limitation of the phone's system? Can it be bypassed with root access or a Magisk module?