-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the option to Cast the Phone Camera instead of the hole phone screen #241
Comments
I'm working on a Pull Request to add this feature to the project. I'm running into a problem and I was wondering if someone could help me. When I try to open the camera inside the server I get the permission error bellow. I'm not sure how can I register permissions since this isn't a complete app. Any ideas of how can I do it?
|
You can't 😞 There are several reasons to add support for installing a real APK. The main one is forwarding audio using Android 10 API. For now, I can't make it work: https://github.com/rom1v/qaudio There is also the need for an IME for entering non-ASCII chars. And now there is the camera capture… |
Meanwhile, I have found Open Camera which supports hiding all UI. Share that with scrcpy ... |
As lots people are doing videochats currently (for obvious reasons), it would be even greater to have this feature. And then we would obviously need to find a way to simulate a camera input device on the computer so that we can use the smartphone as a webcam (of course we could just do screensharing if I am asking for too much here). This way, scrcpy would have the same functionality as DroidCam and so on but greater as you just have to enable ADB once, not start an app every time. And of course free and open source. It is such a pity - I have this camera on my phone that is more than enough for videochats but I would need to install a closed-source driver. scrcpy is good already but this feature would make it brilliant. |
I also have come here after using a couple non-free Android-as-webcam applications. Personally I've used DroidCam and Iriun Webcam. scrcpy + v4l2loopback + OpenCamera works quite well for me on Linux. I keep Iriun Webcam installed in case I am using Windows. One interesting thing I noticed about Open Camera is the Video frame rate and Video bitrate debug options appear to affect the preview, so I was able to get quite smooth result by setting the preview framerate to 60FPS, as well I can lower the preview bitrate from its default on my Google Pixel (sailfish) of around 33Mbps to something closer to the 6Mbps I set when using scrcpy + v4l2loopback, with the hope that this would lower the power consumption of the phone.
I have been imaging what the problems might be with it, and have grown just slightly frustrated that I don't actually understand more concretely what any of them are! I'm just going to list a couple vague impressions I've been carrying with me.
edit: H.264 encoding API, not decoding API |
Please make it real! |
Refs #3049 (comment) |
Update to #3049 (comment), I'm trying to add camera mirror support to Scrcpy.
Example output of ./scrcpy --list-cameras
scrcpy 2.1.1 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO: --> (tcpip) emulator-5554 device Android_SDK_built_for_x86_64
D:\dev\yume-chan\scrcpy-devcontainer\scrcpy\dist\scrcpy-wi...file pushed, 0 skipped. 106.2 MB/s (60911 bytes in 0.001s)
[server] INFO: List of cameras:
--video-source=camera --camera=0 (Back, 1280x720)
--video-source=camera --camera=1 (Front, 1920x1080) Version compatibility:
Future works:
EDIT: In regard to #994 on XiaoMi devices caused by using Sadly MIUI added another one when accessing camera: ./scrcpy --video-source=camera --camera=0 --no-audio
scrcpy 2.1.1 <https://github.com/Genymobile/scrcpy>
INFO: --video-source camera disables control
INFO: ADB device found:
INFO: --> (usb) 73294bba device M2011K2C
D:\dev\yume-chan\scrcpy-devcontainer\scrcpy\dist\scrcpy-wi... file pushed, 0 skipped. 70.6 MB/s (60911 bytes in 0.001s)
[server] INFO: Device: [Xiaomi] Xiaomi M2011K2C (Android 13)
INFO: Renderer: direct3d
java.lang.ClassNotFoundException: miui.tipclose.impl.TipHelpersManager
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at java.lang.Class.forName(Class.java:379)
at miui.tipclose.TipHelperProxy.<init>(TipHelperProxy.java:28)
at miui.tipclose.TipHelperProxy.<clinit>(TipHelperProxy.java:20)
at miui.tipclose.TipHelperProxy.getInstance(TipHelperProxy.java:52)
at android.hardware.CameraInjector.showTipViewForCamera(CameraInjector.java:806)
at android.hardware.camera2.impl.CameraExtImplXiaoMi.cameraOpened(CameraExtImplXiaoMi.java:125)
at android.hardware.camera2.impl.CameraExtStub.cameraOpened(CameraExtStub.java:198)
at android.hardware.camera2.CameraManager$CameraManagerGlobal.onCameraOpenedLocked(CameraManager.java:2611)
at android.hardware.camera2.CameraManager$CameraManagerGlobal.onCameraOpened(CameraManager.java:2580)
at android.hardware.ICameraServiceListener$Stub.onTransact(ICameraServiceListener.java:192)
at android.os.Binder.execTransactInternal(Binder.java:1290)
at android.os.Binder.execTransact(Binder.java:1249)
Caused by: java.lang.ClassNotFoundException: miui.tipclose.impl.TipHelpersManager
... 14 more
INFO: Texture: 5920x2664
WARN: Killing the server... (It still works) |
I was considering investigating camera for scrcpy in a few months, but that's great, you did all the work 😄 Thank you. I have not tested yet (I'm on my phone, I will not have access to my computer until the end of the month).
I think we don't need this, the camera (like the display) is selected for the whole scrcpy instance. This would add complexity and cause issues (for example with V4L2). If I remember correctly, each camera supports a set of predefined resolutions (which can be listed). Contrary to screen capture, the aspect ratio is not fixed, so By the way, IIRC cameras expose different resolution for portrait and landscape (1080×1920 and 1920×1080), so this can be used to solve the 90° rotation. IMO we should reset the camera capture on device rotation (so that it works the same way as screen capture), unless
Why? The same hack does not work? Or is it just more complicated due to callbacks?
Related (just an idea): the camera selection could print the results the same way as the adb device selection (with a Thank you again for your work. |
I listed some features camera and video chat/conference apps commonly support:
I can't think of any use case that requires a specific aspect ratio. I will only choose 16:9 aspect ratio in first version, and wait for feedbacks for use cases of other aspect ratios.
This should require the use of accelerometer (if our Android Shell app had this permission). Camera apps can rotate its UI when screen rotation is locked, and show the "photo direction" indicator when the device is nearly parallel to the ground, so they should be already using the accelerometer. I will check some open-sourced camera apps for inspirations. But this is definitely a hard task. It it's not possible, the users can always manually rotate the displayed texture using keyboard shortcuts, except that it won't be recorded. If it's possible, another implementation is sending the device's exact orientation to the client, and let the client rotate the displayed texture. I mean it can rotate freely, not in 90 degrees increment. So for camera mirroring, the displayed image always has the correct rotation. It can also be useful for mirroring racing games that use accelerometer to steer, and render the scene in reverse to the device rotation. Like this
I have converted callbacks into synchronous calls using a worker thread. The difficulty is at coordinating with audio starting. My plan is starting the workaround in
So it would always print camera list? Or only when some option combinations? |
Update:
Here is a Windows x64 build for testing: scrcpy-win64-v2.1.1-14-g51d29fa5.zip Usage:
|
@yume-chan Thank you for you work 👍 I just tested your branch, with just the following diff: diff --git a/app/src/server.c b/app/src/server.c
index c8f7c31df..bb78850f0 100644
--- a/app/src/server.c
+++ b/app/src/server.c
@@ -247,7 +247,7 @@ execute_server(struct sc_server *server,
sc_server_get_codec_name(params->audio_codec));
}
if (params->video_source != SC_VIDEO_SOURCE_DISPLAY){
- assert(params->audio_source == SC_VIDEO_SOURCE_CAMERA);
+ assert(params->video_source == SC_VIDEO_SOURCE_CAMERA);
ADD_PARAM("video_source=camera");
}
if (params->audio_source != SC_AUDIO_SOURCE_OUTPUT) { Here are some bug reports (as a simple user, I haven't investigated at all). I run with:
I get one frame, but it stays frozen. Also, on my phone,
That's probably minor things 😉 Could you please rebase your branch on current
Ah yes, we could not reuse the rotation listener. Maybe the shortcut MOD+r can be re-used for camera capture rotation then :)
👍
I don't know. Why not. |
Add --video-source=camera, and related options: - --camera-id=<id>: select the camera by its id (see --list-cameras); - --camera-size=<width>x<height>: select the capture size. Fixed #241 <#241> PR #4213 <#4213> Co-authored-by: Romain Vimont <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
Add --video-source=camera, and related options: - --camera-id=<id>: select the camera by its id (see --list-cameras); - --camera-size=<width>x<height>: select the capture size. Fixed #241 <#241> PR #4213 <#4213> Co-authored-by: Romain Vimont <[email protected]> Signed-off-by: Romain Vimont <[email protected]>
Implemented in scrcpy v2.2. |
A lot of us are looking for apps like:
When you have an already working app that Casts all the phone in a better resolution and with much less lag! I can just open the camera app in my phone but you can imagine the problems with it.
please add this functionality (Y)
The text was updated successfully, but these errors were encountered: