mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.56k stars 1.1k forks source link

🐛 Failed to get maximum FPS for Camera ID 1 #3288

Closed francesco-clementi-92 closed 1 day ago

francesco-clementi-92 commented 1 day ago

What's happening?

I'm trying to develop a frame processor plugin, but when I start my application I get the errors on android:

Failed to get maximum FPS for Camera ID 1! Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                        at com.mrousavy.camera.core.utils.CamcorderProfileUtils$Companion.getMaximumFps(CamcorderProfileUtils.kt:90)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.getFormats(CameraDeviceDetails.kt:132)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.toMap(CameraDeviceDetails.kt:84)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.getDevicesJson(CameraDevicesManager.kt:87)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.sendAvailableDevicesChangedEvent(CameraDevicesManager.kt:94)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager$initialize$1.invokeSuspend(CameraDevicesManager.kt:71)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)

Reproduceable Code

export default function App() {
  const { hasPermission, requestPermission } = useCameraPermission();
  const { detectPlate } = createVisionCameraAPLRPlugin();
  const cameraDevice = useCameraDevice('back');

  useEffect(() => {
    if (hasPermission) return;
    requestPermission();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  const frameProcessor = useFrameProcessor((frame) => {
    'worklet';
    const objects = detectPlate(frame);
    console.log(JSON.stringify(objects));
  }, []);

  return (
    <View
      style={[
        StyleSheet.absoluteFill,
        {
          alignItems: 'center',
          justifyContent: 'center',
        },
      ]}
    >
      {hasPermission && cameraDevice ? (
        <>
          <>
            <Camera
              style={StyleSheet.absoluteFill}
              device={cameraDevice}
              frameProcessor={frameProcessor}
              isActive={true}
            />
          </>
        </>
      ) : (
        <Text
          style={{
            width: '100%',
            backgroundColor: 'rgb(255,0,0)',
            textAlign: 'center',
            color: 'white',
          }}
        >
          No camera device or permission
        </Text>
      )}
    </View>
  );
}

Relevant log output

2024-11-12 15:36:27.348 29156-29252 Camera2Enc...esProvider visioncameraopenalpr.example         D  EncoderProfiles contains invalid video profiles, use CamcorderProfile to create EncoderProfilesProxy.
2024-11-12 15:36:27.348 29156-29252 EncoderPro...roxyCompat visioncameraopenalpr.example         W  Should use from(EncoderProfiles) on API 33instead. CamcorderProfile is deprecated on API 31.
2024-11-12 15:36:27.348 29156-29252 CapabilitiesByQuality   visioncameraopenalpr.example         D  profiles = ImmutableEncoderProfilesProxy{defaultDurationSeconds=30, recommendedFileFormat=2, audioProfiles=[AudioProfileProxy{codec=3, mediaType=audio/mp4a-latm, bitrate=192000, sampleRate=48000, channels=2, profile=2}], videoProfiles=[VideoProfileProxy{codec=2, mediaType=video/avc, bitrate=20000000, frameRate=30, width=1920, height=1080, profile=-1, bitDepth=8, chromaSubsampling=0, hdrFormat=0}]}
2024-11-12 15:36:27.348 29156-29252 Camera2Enc...esProvider visioncameraopenalpr.example         D  EncoderProfiles contains invalid video profiles, use CamcorderProfile to create EncoderProfilesProxy.
2024-11-12 15:36:27.348 29156-29252 EncoderPro...roxyCompat visioncameraopenalpr.example         W  Should use from(EncoderProfiles) on API 33instead. CamcorderProfile is deprecated on API 31.
2024-11-12 15:36:27.348 29156-29252 CapabilitiesByQuality   visioncameraopenalpr.example         D  profiles = ImmutableEncoderProfilesProxy{defaultDurationSeconds=30, recommendedFileFormat=2, audioProfiles=[AudioProfileProxy{codec=3, mediaType=audio/mp4a-latm, bitrate=192000, sampleRate=48000, channels=2, profile=2}], videoProfiles=[VideoProfileProxy{codec=2, mediaType=video/avc, bitrate=14000000, frameRate=30, width=1280, height=720, profile=-1, bitDepth=8, chromaSubsampling=0, hdrFormat=0}]}
2024-11-12 15:36:27.349 29156-29252 Camera2Enc...esProvider visioncameraopenalpr.example         D  EncoderProfiles contains invalid video profiles, use CamcorderProfile to create EncoderProfilesProxy.
2024-11-12 15:36:27.349 29156-29252 EncoderPro...roxyCompat visioncameraopenalpr.example         W  Should use from(EncoderProfiles) on API 33instead. CamcorderProfile is deprecated on API 31.
2024-11-12 15:36:27.349 29156-29252 CapabilitiesByQuality   visioncameraopenalpr.example         D  profiles = ImmutableEncoderProfilesProxy{defaultDurationSeconds=30, recommendedFileFormat=2, audioProfiles=[AudioProfileProxy{codec=3, mediaType=audio/mp4a-latm, bitrate=192000, sampleRate=48000, channels=2, profile=2}], videoProfiles=[VideoProfileProxy{codec=2, mediaType=video/avc, bitrate=2000000, frameRate=30, width=720, height=480, profile=-1, bitDepth=8, chromaSubsampling=0, hdrFormat=0}]}
2024-11-12 15:36:27.351 29156-29252 CamcorderProfileUtils   visioncameraopenalpr.example         E  Failed to get maximum FPS for Camera ID 1! Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                        at com.mrousavy.camera.core.utils.CamcorderProfileUtils$Companion.getMaximumFps(CamcorderProfileUtils.kt:90)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.getFormats(CameraDeviceDetails.kt:132)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.toMap(CameraDeviceDetails.kt:84)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.getDevicesJson(CameraDevicesManager.kt:87)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.sendAvailableDevicesChangedEvent(CameraDevicesManager.kt:94)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager$initialize$1.invokeSuspend(CameraDevicesManager.kt:71)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2024-11-12 15:36:27.364 29156-29252 CamcorderProfileUtils   visioncameraopenalpr.example         E  Failed to get maximum FPS for Camera ID 1! Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                        at com.mrousavy.camera.core.utils.CamcorderProfileUtils$Companion.getMaximumFps(CamcorderProfileUtils.kt:90)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.getFormats(CameraDeviceDetails.kt:132)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.toMap(CameraDeviceDetails.kt:84)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.getDevicesJson(CameraDevicesManager.kt:87)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.sendAvailableDevicesChangedEvent(CameraDevicesManager.kt:94)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager$initialize$1.invokeSuspend(CameraDevicesManager.kt:71)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2024-11-12 15:36:27.377 29156-29252 CamcorderProfileUtils   visioncameraopenalpr.example         E  Failed to get maximum FPS for Camera ID 1! Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                        at com.mrousavy.camera.core.utils.CamcorderProfileUtils$Companion.getMaximumFps(CamcorderProfileUtils.kt:90)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.getFormats(CameraDeviceDetails.kt:132)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.toMap(CameraDeviceDetails.kt:84)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.getDevicesJson(CameraDevicesManager.kt:87)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.sendAvailableDevicesChangedEvent(CameraDevicesManager.kt:94)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager$initialize$1.invokeSuspend(CameraDevicesManager.kt:71)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2024-11-12 15:36:27.389 29156-29252 CamcorderProfileUtils   visioncameraopenalpr.example         E  Failed to get maximum FPS for Camera ID 1! Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.EncoderProfiles$VideoProfile.getFrameRate()' on a null object reference
                                                                                                        at com.mrousavy.camera.core.utils.CamcorderProfileUtils$Companion.getMaximumFps(CamcorderProfileUtils.kt:90)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.getFormats(CameraDeviceDetails.kt:132)
                                                                                                        at com.mrousavy.camera.core.CameraDeviceDetails.toMap(CameraDeviceDetails.kt:84)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.getDevicesJson(CameraDevicesManager.kt:87)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager.sendAvailableDevicesChangedEvent(CameraDevicesManager.kt:94)
                                                                                                        at com.mrousavy.camera.react.CameraDevicesManager$initialize$1.invokeSuspend(CameraDevicesManager.kt:71)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)

Camera Device

{
  "formats": [],
  "sensorOrientation": "landscape-left",
  "hardwareLevel": "full",
  "maxZoom": 10,
  "minZoom": 1,
  "maxExposure": 24,
  "supportsLowLightBoost": false,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "isMultiCam": false,
  "minFocusDistance": 10,
  "minExposure": -24,
  "name": "0 (BACK) androidx.camera.camera2",
  "hasFlash": true,
  "hasTorch": true,
  "position": "back",
  "id": "0"
}

Device

Xiaomi redmi note 10 - Android 13

VisionCamera Version

4.6.1

Can you reproduce this issue in the VisionCamera Example app?

I didn't try (⚠️ your issue might get ignored & closed if you don't try this)

Additional information

maintenance-hans[bot] commented 1 day ago

Guten Tag, Hans here. Vielen Dank for your report, but it seems you did not try reproducing the issue in the VisionCamera Example app. Please follow the template and provide all relevant logs, especially from adb logcat, so mrousavy can properly address your issue in a timely manner. If you want faster responses, consider supporting the project on GitHub Sponsors. 🍻

Note: If you think I made a mistake by closing this issue, please ping @mrousavy to take a look.