Skip to content
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

Flutter doesn't recognise external USB camera #42413

Open
hamid-yousefi opened this issue Oct 10, 2019 · 58 comments
Open

Flutter doesn't recognise external USB camera #42413

hamid-yousefi opened this issue Oct 10, 2019 · 58 comments
Labels
c: new feature Nothing broken; request for a new capability p: camera The camera plugin P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team

Comments

@hamid-yousefi
Copy link

Use case

Not recognizing external USB camera

Proposal

Hi, I want to use my external usb camera but flutter does not recognize it, it just finds my rear and my front cameras. Please take a look at it .

Thank you

@janmoppel janmoppel changed the title External USB camera Flutter doesn't recognise external USB camera Oct 10, 2019
@janmoppel janmoppel added p: camera The camera plugin c: new feature Nothing broken; request for a new capability p: first party labels Oct 10, 2019
@haamaanaa
Copy link

Hi! Is there plans to add support for external cameras in next camera library version?

#31225 does not answer this directly....

@AshwinPrabhuB
Copy link

AshwinPrabhuB commented Jan 6, 2020

Is external camera access a vendor/device dependant capability?

@moeiscool
Copy link

this and SD card support would be golden 🙏

@crabio
Copy link

crabio commented Sep 21, 2020

Hi!
Do you have any updates about this feature?
I need this for my app and one way it is Flutter + Kotlin code for Android

@josephjmanavalan

This comment has been minimized.

@khalid-alsaleh-dev

This comment has been minimized.

@aponski

This comment has been minimized.

@mcemkilinc

This comment has been minimized.

@Artespecialist

This comment has been minimized.

@hariangr

This comment has been minimized.

@mat-his
Copy link

mat-his commented May 5, 2021

Take a look at this plugin, I haven't tested it yet, but it may help.

https://pub.dev/packages/flir_plugin

@jerossh

This comment has been minimized.

@stuartmorgan stuartmorgan added the P3 Issues that are less important to the Flutter project label May 13, 2021
@Chance212
Copy link

case CameraLensDirection.back:
return Icons.camera_rear;
case CameraLensDirection.front:
return Icons.camera_front;
case CameraLensDirection.external:
return Icons.camera;

/// External camera which may not be mounted to the device.

I see there is a case for external but is it working i tried with different apps for USB camera and it didnt for me :( any luck someone else ?

@vrichv

This comment has been minimized.

@RomanIvn

This comment was marked as off-topic.

@Dairyo-Gokan
Copy link

Which target device are you talking about?
If you're talking about the device with Android 10 (Q), did you see the link below?

Still unable to get USB Video device permission on Android 10
https://issuetracker.google.com/issues/145082934

@unoravi

This comment has been minimized.

@mat-his
Copy link

mat-his commented Nov 10, 2021

I'm currently trying to design a Flutter plugin for controlling external UVC cameras (webcams), using the Android libraries described in this article : external usb cameras

Nevertheless, one should keep in mind that even on native Android the use of external USB cameras is quite limited.

@venkatapathiraj

This comment has been minimized.

@Leterax

This comment was marked as off-topic.

@unoravi

This comment was marked as off-topic.

1 similar comment
@unoravi

This comment was marked as off-topic.

@Taverz
Copy link

Taverz commented Feb 16, 2023

Please, help!!
Do you need to urgently solve the problem, even if it is some kind of temporary solution or workaround?
Is it possible to somehow hardcode certain parameters or data to make the plugin work?

Device Feature:

  • Android 12
  • Android SDK 32
  • Does not have cameras
  • Lots of USB ports

Android Studio from M1-Apple

flutter doctor -v flutter doctor -v [✓] Flutter (Channel stable, 3.7.1, on macOS 13.2 22D49 darwin-arm64, locale ru-RU) • Flutter version 3.7.1 on channel stable at /Users/User/Documents/devflutter/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 7048ed9 (2 weeks ago), 2023-02-01 09:07:31 -0800 • Engine revision 800594f1f4 • Dart version 2.19.1 • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/User/Library/Android/sdk
• Platform android-33, build-tools 30.0.3
• ANDROID_HOME = /Users/User/Library/Android/sdk
• Java binary at: /Users/User/.sdkman/candidates/java/current/bin/java
• Java version OpenJDK Runtime Environment Zulu11.52+13-CA (build 11.0.13+8-LTS)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14B47b
• CocoaPods version 1.11.3

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2022.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.

[✓] VS Code (version 1.75.0)
• VS Code at /Users/User/Documents/Visual Studio Code.app/Contents
• Flutter extension version 3.58.0

[✓] Connected device (3 available)
• rk3588 (mobile) • ISCH6N81SS • android-arm64 • Android 12 (API 32)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.2 22D49 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
• All required HTTP hosts are available

! Doctor found issues in 1 category.

  1. I connected an external camera via USB.
  2. I checked that the camera is working: I went into the system application camera, camera !! works.
  3. Tried a simple android.hardware.camera2 example (run android code): !! works (external camera success): the camera sees and successfully displays the image from it.
  4. I took the last sample code from branch=main https://github.com/flutter/plugins/tree/main/packages/camera/camera
  5. Launched as Flutter debug
  6. Application started successfully
  7. Clicked on select EXTERNAL camera (connect via USB).
  8. ERRORE : !!!!!!! android.media.CamcorderProfile.getAll // android.media.CamcorderProfile.native_get_camcorder_profiles

(I tried to change the java code but without success)

Log errore

Launching lib/main.dart on rk3588 in debug mode...
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:56408/dxxd9TAdu50=/ws
I/CameraManagerGlobal(16481): Connecting to camera service
E/MediaProfiles(16481): The given camcorder profile camera 101 quality 0 is not found

After tap select camera EXTERNAL
-> ->
E/MethodChannel#plugins.flutter.io/camera(16481): Failed to handle method call
E/MethodChannel#plugins.flutter.io/camera(16481): java.lang.RuntimeException: Error retrieving camcorder profile params
E/MethodChannel#plugins.flutter.io/camera(16481): at android.media.CamcorderProfile.native_get_camcorder_profiles(Native Method)
E/MethodChannel#plugins.flutter.io/camera(16481): at android.media.CamcorderProfile.getAll(CamcorderProfile.java:605)
E/MethodChannel#plugins.flutter.io/camera(16481): at io.flutter.plugins.camera.features.resolution.ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset(ResolutionFeature.java:231)
E/MethodChannel#plugins.flutter.io/camera(16481): at io.flutter.plugins.camera.features.resolution.ResolutionFeature.configureResolution(ResolutionFeature.java:278)
E/MethodChannel#plugins.flutter.io/camera(16481): at io.flutter.plugins.camera.features.resolution.ResolutionFeature.(ResolutionFeature.java:53)
E/MethodChannel#plugins.flutter.io/camera(16481): at io.flutter.plugins.camera.features.CameraFeatureFactoryImpl.createResolutionFeature(CameraFeatureFactoryImpl.java:58)
E/MethodChannel#plugins.flutter.io/camera(16481): at io.flutter.plugins.camera.features.CameraFeatures.init(CameraFeatures.java:71)
E/MethodChannel#plugins.flutter.io/camera(16481): at io.flutter.plugins.camera.Camera.(Camera.java:215)
E/MethodChannel#plugins.flutter.io/camera(16481): at io.flutter.plugins.camera.MethodCallHandlerImpl.instantiateCamera(MethodCallHandlerImpl.java:385)
E/MethodChannel#plugins.flutter.io/camera(16481): at io.flutter.plugins.camera.MethodC

@Taverz
Copy link

Taverz commented Feb 16, 2023

Снимок экрана 2023-02-16 в 10 13 36

When testing the latest version of the example, on a tablet without cameras, I attached an external camera. The external ka recognizes. @hamid811394

@Taverz
Copy link

Taverz commented Feb 16, 2023

android 12 external camera recognizes

@Taverz
Copy link

Taverz commented Feb 16, 2023

!!!!!!!!!!!!!!!!! After it recognizes the camera, the application works with it and crashes.

@Taverz
Copy link

Taverz commented Feb 16, 2023

#120776. #120776

@Taverz
Copy link

Taverz commented Feb 16, 2023

Снимок экрана 2023-02-16 в 10 37 55

@Taverz
Copy link

Taverz commented Feb 16, 2023

Solution errore: retrieving camcorder profile params.

This file redacted:

  • MediaRecorderBuilder.java
  • Camera.java.
  • ResolutionFeature.java.

Delete field:

  • CamcorderProfile.
  • EncoderProfiles.

Method editing.

  public MediaRecorder build() throws IOException, NullPointerException, IndexOutOfBoundsException {
    MediaRecorder mediaRecorder = recorderFactory.makeMediaRecorder();

    // There's a fixed order that mediaRecorder expects. Only change these functions accordingly.
    // You can find the specifics here: https://developer.android.com/reference/android/media/MediaRecorder.
    if (enableAudio) mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);

    if (Build.VERSION.SDK_INT >= 31) {
//      EncoderProfiles.VideoProfile videoProfile = encoderProfiles.getVideoProfiles().get(0);
//      EncoderProfiles.AudioProfile audioProfile = encoderProfiles.getAudioProfiles().get(0);
      String vvvww =" WIN == " ;
//      vvvww = vvvww + " getRecommendedFileFormat "+ encoderProfiles.getRecommendedFileFormat() ;
//      if (enableAudio) {
//        vvvww = vvvww + " getCodec "+ audioProfile.getCodec();
//        vvvww = vvvww + " getBitrate "+ audioProfile.getBitrate();
//        vvvww = vvvww + " getSampleRate "+ audioProfile.getSampleRate();
//      }
//      vvvww = vvvww + " videoProfile.getCodec "+ videoProfile.getCodec();
//      vvvww = vvvww + " videoProfile.getBitrate "+ videoProfile.getBitrate();
//      vvvww = vvvww + " videoProfile.getFrameRate "+ videoProfile.getFrameRate();
//
//      vvvww = vvvww + " videoProfile.getWidth "+ videoProfile.getWidth();
//      vvvww = vvvww + " videoProfile.getHeight "+ videoProfile.getHeight();


      Log.e("EncoderProfilesWWWW", vvvww);

//      MediaRecorder.OutputFormat.DEFAULT  // encoderProfiles.getRecommendedFileFormat()
      mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
//      if (enableAudio) {
//        // 0 - 7 // 2
//        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); //audioProfile.getCodec());
////        mediaRecorder.setAudioEncodingBitRate(audioProfile.getBitrate());
////        mediaRecorder.setAudioSamplingRate(audioProfile.getSampleRate());
//      }
      // 0 - 5 // 3
      mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); // mediaRecorder.setVideoEncoder(videoProfile.getCodec());
      // ??
//      mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate());
      // 0 , 90, ...
//      mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate());
      // me size
      mediaRecorder.setVideoSize(600, 600); // videoProfile.getWidth(), videoProfile.getHeight());
      mediaRecorder.setVideoSize(600, 600);
    } else {
      /// MediaRecorder.OutputFormat.RAW_AMR
      // mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);  //camcorderProfile.fileFormat);
      // if (enableAudio) {
      //   mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);  //camcorderProfile.audioCodec);
      //   mediaRecorder.setAudioEncodingBitRate(16); //camcorderProfile.audioBitRate
      //   mediaRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate);
      // }
      // mediaRecorder.setVideoEncoder(camcorderProfile.videoCodec);
      // mediaRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate);
      // mediaRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
      // mediaRecorder.setVideoSize(
      //     camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight);
    }

    mediaRecorder.setOutputFile(outputFilePath);
    mediaRecorder.setOrientationHint(this.mediaOrientation);

    mediaRecorder.prepare();

    return mediaRecorder;
  }

@KennyTC

This comment was marked as off-topic.

@Taverz
Copy link

Taverz commented Mar 5, 2023

@KennyTC Hello. I'm not sure if an external camera will work on the emulator. Another problem is that if there is an internal chamber, the external chamber may not open.

@ZateLabClients
Copy link

@Taverz
Hi @Taverz , can u please help me with this error?

In android 12, external camera works well in system camera app.
In flutter package, shows "No capture session available for current capture session"

When i inspect ResolutionFeature.java, i found the following condition is not met:
if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
}

Then i tried to return "return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);" without checking the above condition, following error shows:

E/MediaProfiles(15037): The given camcorder profile camera 100 quality 0 is not found
E/MethodChannel#plugins.flutter.io/camera_android(15037): Failed to handle method call
E/MethodChannel#plugins.flutter.io/camera_android(15037): java.lang.RuntimeException: Error retrieving camcorder profile params
E/MethodChannel#plugins.flutter.io/camera_android(15037): at android.media.CamcorderProfile.native_get_camcorder_profiles(Native Method)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at android.media.CamcorderProfile.getAll(CamcorderProfile.java:605)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.features.resolution.ResolutionFeature.getBestAvailableCamcorderProfileForResolutionPreset(ResolutionFeature.java:254)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.features.resolution.ResolutionFeature.configureResolution(ResolutionFeature.java:281)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.features.resolution.ResolutionFeature.(ResolutionFeature.java:55)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.features.CameraFeatureFactoryImpl.createResolutionFeature(CameraFeatureFactoryImpl.java:62)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.features.CameraFeatures.init(CameraFeatures.java:74)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.Camera.(Camera.java:210)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.MethodCallHandlerImpl.instantiateCamera(MethodCallHandlerImpl.java:401)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.MethodCallHandlerImpl.lambda$onMethodCall$0$io-flutter-plugins-camera-MethodCallHandlerImpl(MethodCallHandlerImpl.java:82)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.MethodCallHandlerImpl$$ExternalSyntheticLambda0.onResult(Unknown Source:6)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.CameraPermissions.requestPermissions(CameraPermissions.java:69)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugins.camera.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:75)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at android.os.Looper.loopOnce(Looper.java:201)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at android.os.Looper.loop(Looper.java:288)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at android.app.ActivityThread.main(ActivityThread.java:7870)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/MethodChannel#plugins.flutter.io/camera_android(15037): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I/flutter (15037): Error: error
I/flutter (15037): Error Message: Error retrieving camcorder profile params

I tried @Taverz your solution but no luck.
Can you help me please.

@Taverz
Copy link

Taverz commented May 5, 2023

I can give you my working code for you to try, I can't help you with anything else.

  1. Whether the camera device is detected:

    • Open system camera app and see
    • Or request a connected list of connected devices via starrony
  2. Download and unpack the folder by placing it in the root directory.
    https://drive.google.com/file/d/1niY4Pkuijs-EV7Sfzt_x6ks6HfN3GE-4/view?usp=share_link

  3. Specify dependencies on the file like this:

    camera:
    ㅤpath: camera # or this path ./camera

  4. Test

@Taverz

This comment was marked as off-topic.

@stuartmorgan

This comment was marked as off-topic.

@ZateLabClients

This comment was marked as off-topic.

@arunsinger

This comment was marked as off-topic.

@devmarwat

This comment was marked as off-topic.

@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
@Hixie Hixie removed the plugin label Jul 6, 2023
@flutter-triage-bot flutter-triage-bot bot added team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels Jul 8, 2023
@stuartmorgan stuartmorgan added the platform-android Android applications specifically label Jul 9, 2023
@ethandvaughan

This comment was marked as off-topic.

@rahulbroadview
Copy link

here

Hi Pranav,
Did you get the solution for that?

@djensen47
Copy link

If the Flutter team needs a use case for this: embedded systems. Particularly kiosks. But this could be used for infotainment systems and so on.

@balaji101010
Copy link

Hi @Taverz can you please add your working code as a git repo? is it possible for you?

@eleminer
Copy link

eleminer commented Apr 9, 2024

Any update on this ?

@Joao-Peterson
Copy link

tested the flutter camera example project and one i made myself and could't get any of the apps to even list the OTG Camera with availableCameras().

Tested with Physical Android 9 and 13.

flutter doctor -v:

[✓] Flutter (Channel , 3.19.5, on Linux 6.8.1-arch1-1, locale en_US.UTF-8)
    • Flutter version 3.19.5 on channel  at /usr/lib/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision archlinuxaur (unknown (arch linux aur package)), 2038-01-19 03:14:08
    • Engine revision e76c95649884
    • Dart version 3.3.2
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /opt/android-sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /opt/android-sdk
    • ANDROID_SDK_ROOT = /opt/android-sdk
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.2+13)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 17.0.6
    • cmake version 3.28.3
    • ninja version 1.11.1
    • pkg-config version 2.1.1

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (2 available)
    • ASUS X01AD (mobile) • 192.168.0.101:5555 • android-arm64 • Android 9 (API 28)
    • Linux (desktop)     • linux              • linux-x64     • Linux 6.8.1-arch1-1

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

@eleminer
Copy link

eleminer commented May 8, 2024

any solutions for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability p: camera The camera plugin P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team
Projects
None yet
Development

No branches or pull requests