apivideo / api.video-flutter-live-stream

Flutter RTMP live stream client. Made with ♥ by api.video
MIT License
62 stars 37 forks source link

External camera support (along with front and back cameras) #20

Open abbas2501 opened 1 year ago

abbas2501 commented 1 year ago

Thanks for the amazing package! I have a use case where I need to use a third camera (a webcam) connected to my phone (alongside the front and back cameras).

Describe the solution you'd like Ability to switch between three cameras (or more in a loop) using the switch camera button.

ThibaultBee commented 1 year ago

Hi,

Glad you like the project :)

This is a huge work and we are not sure that that the native iOS and Android library we used does support external camera and we are not even sure that iOS and Android phone support to connect a third camera. We are not going to implement this in short term or medium term. We do not have the resources for this but if you submit a PR we will definitely have a look on it 👍

I am curious though. How is the third camera connected? USB or Wi-Fi? What type of camera it is?

abbas2501 commented 1 year ago

HI @ThibaultBee

Thanks for reverting!

For the last part of your comment - Its just another web camera connected via OTG to the android phone. I'm able to use the camera on dedicated apps for this use case. One for example - USB Camera App

I'm unsure of iOS but android does support more cameras than the native device cameras.

For example - take a look at this flutter package for RTMP streaming (i used is previously in our app but it doesn't seem to be well maintained and has bugs, this is when I moved to yours, and it's been a fruitful switch). The package has a method that returns a list of all cameras (front, back, external). Probably it can be a starting point in building out this support. Will look into it. video_stream

I'll look into creating a PR if I find success in trying it out.

Thanks!

abbas2501 commented 1 year ago

Hi @ThibaultBee

Here's an update from my research so far -

Along with LENS_FACING_BACK & LENS_FACING_FRONT we also have - LENS_FACING_EXTERNAL

This gives us access to external cameras. For this, changes are required on your StreamPack package, which only exposes getFrontCameras and getBackCameras on LENS_FACING_FRONT & LENS_FACING_BACK respectively. If it can expose a new method getExternalCameras() based on LENS_FACING_EXTERNAL, that will do the work.

I have created a fork for myself of the StreamPack package but I'm stuck at importing the fork into the flutter package (instead of the original StreamPack package).

Will you entertain a PR on StreamPack? I've added one single method getExternalCameras().

Thanks!

ThibaultBee commented 1 year ago

Nice ;)

Yes, I can accept PR on StreamPack as well.

tibfox commented 1 year ago

woudl be great to also have influence on the initial orientation of the selected camera. if I switch from landscape-back to front the orientation is portrait in default. If I switch back to the back camera it is still portrait even thought it has been landscape before.

ThibaultBee commented 1 year ago

@tibfox sorry I miss your message. As your issue is not related, please open a new issue.

@abbas2501 If you use CameraPosition.other it will use the external camera if one is connected and detected by camera2. There are still no way to return the camera list.

shabirsaddique1 commented 4 months ago

Any updates related to the external camera connection tried CameraPosition.other but still, it returned an exception failed to set the camera position, and the empty list in returned but the camera is connected with the phone through OTG. I was able to connect the external camera to Android native but was not able to send an external video source so it could start streaming through that external source.

ThibaultBee commented 4 months ago

External cameras are supported via camera2 API but this have never been tested because I don't have a phone that supports external cameras.

I am not sure an Android device support external cameras via camera2.

There is feature flag to check if your device supports this feature: see https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_CAMERA_EXTERNAL

Could you test something like that:


/**
 * Get if the system supports the given feature.
 *
 * @param featureName the feature name from [PackageManager.FEATURE_*]
 * @return true if the feature is supported, false otherwise
 */
fun Context.hasSystemFeature(featureName: String) = packageManager.hasSystemFeature(featureName)

/**
 * Get if the system supports external cameras.
 *
 * @return true if the feature is supported, false otherwise
 */
fun Context.hasExternalCamera() = hasSystemFeature(PackageManager.FEATURE_CAMERA_EXTERNAL)

Then, run:

Log.e("TEST", "External camera support: ${context.hasExternalCamera()}")