mrousavy / react-native-vision-camera

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

🐛 Error when starting to record: `MediaRecorder Error: 268435556 (-1007)` #2443

Closed jamesbayy closed 5 months ago

jamesbayy commented 7 months ago

What's happening?

When starting recording, App Clash on the Huawei device。But it runs normally on other Android devices

Reproduceable Code

export default function Page() {
    const device = useCameraDevice('back')
    const camera = useRef<Camera>(null)
    const [results, setResults] = useState<string>()
    const startRecording = () => {
        camera.current!.startRecording({
            onRecordingFinished: (video) => {
                setResults(video.path)
            },
            onRecordingError: (error) => console.error(error),
        })
    }
    const stopRecording = async () => {
        await camera.current!.stopRecording()
    }
    return (
        <View style={styles.container}>
            <Camera
                style={StyleSheet.absoluteFill}
                device={device!}
                ref={camera}
                video={true}
                audio={false}
                isActive={true}
            ></Camera>

            <View
                style={{
                    position: 'absolute',
                    width: '100%',
                    bottom: 10,
                    display: 'flex',
                    flexDirection: 'row',
                    justifyContent: 'space-around',
                }}
            >
                <Pressable
                    style={{
                        width: 50,
                        height: 50,
                        margin: 3,
                        backgroundColor: 'green',
                    }}
                    onPress={() => {
                        startRecording()
                    }}
                >
                    <Text>start</Text>
                </Pressable>
                <Pressable
                    style={{
                        width: 50,
                        height: 50,
                        margin: 3,
                        backgroundColor: '#333',
                    }}
                    onPress={() => {
                        stopRecording()
                    }}
                >
                    <Text>stop</Text>
                </Pressable>
                <Pressable
                    style={{
                        width: 50,
                        height: 50,
                        margin: 3,
                        backgroundColor: '#FD3',
                    }}
                    onPress={() => {
                        router.push('/(test)/Result')
                        router.setParams({
                            path: results!,
                        })
                    }}
                >
                    <Text>jump to result</Text>
                </Pressable>
            </View>
        </View>
    )
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
    },
})

Relevant log output

2024-01-26 18:38:30.649 31251-31251 PreviewView             com.jamesbayy.RNcameraBug            I  Setting PreviewView Surface Size to 1158 x 2058...
2024-01-26 18:38:30.652 31251-31251 SurfaceView             com.jamesbayy.RNcameraBug            I  ViewUI setLowResolutionInfo compatInfo.supportsScreen() is not satisfied
2024-01-26 18:38:30.652 31251-31251 CameraSession           com.jamesbayy.RNcameraBug            I  PreviewView Surface updated! Surface(name=null)/@0xc1dcde2 1920 x 1080
2024-01-26 18:38:30.652 31251-31251 HwApsImpl               com.jamesbayy.RNcameraBug            W  not support full screen video recognize feature ## com.jamesbayy.RNcameraBug
2024-01-26 18:38:30.855 31251-31275 BufferQueueProducer     com.jamesbayy.RNcameraBug            E  [SurfaceTexture-0-31251-0](id:7a1300000003,api:4,p:1827,c:31251) dequeueBuffer: BufferQueue has been abandoned
2024-01-26 18:38:31.092 31251-32489 CreateCaptureSession    com.jamesbayy.RNcameraBug            I  Camera #0: Successfully created CameraCaptureSession #2!
2024-01-26 18:38:31.092 31251-31275 CameraDevice-JV-0       com.jamesbayy.RNcameraBug            I  Camera now idle
2024-01-26 18:38:31.092 31251-32489 CameraSession           com.jamesbayy.RNcameraBug            I  Successfully configured Session with 2 outputs for Camera #0!
2024-01-26 18:38:31.092 31251-32489 CameraSession           com.jamesbayy.RNcameraBug            I  Updating Video Outputs...
2024-01-26 18:38:31.092 31251-32489 VideoPipeline           com.jamesbayy.RNcameraBug            I  Removing FrameProcessor Output...
2024-01-26 18:38:31.092 31251-32489 VideoPipeline           com.jamesbayy.RNcameraBug            I  Removing RecordingSession Output...
2024-01-26 18:38:31.096 31251-32489 CameraView              com.jamesbayy.RNcameraBug            I  invokeOnStarted()
2024-01-26 18:38:31.097 31251-32489 CameraSession           com.jamesbayy.RNcameraBug            I  Successfully updated CameraSession Configuration! isActive: true
2024-01-26 18:38:31.099 31251-32489 CreateCaptureSession    com.jamesbayy.RNcameraBug            I  Camera #0: CameraCaptureSession #1 has been closed.
2024-01-26 18:38:31.301 31251-32489 OpenGLContext           com.jamesbayy.RNcameraBug            I  Initializing EGLDisplay..
2024-01-26 18:38:31.301 31251-32489 OpenGLContext           com.jamesbayy.RNcameraBug            I  Initializing EGLConfig..
2024-01-26 18:38:31.302 31251-32489 OpenGLContext           com.jamesbayy.RNcameraBug            I  Initializing EGLContext..
2024-01-26 18:38:31.304 31251-32489 OpenGLContext           com.jamesbayy.RNcameraBug            I  Initializing 1x1 offscreen pbuffer EGLSurface..
2024-01-26 18:38:31.305 31251-32489 VideoPipeline           com.jamesbayy.RNcameraBug            I  Attached Texture to Context 1
2024-01-26 18:38:34.642 31251-31267 System                  com.jamesbayy.RNcameraBug            W  A resource failed to call release. 
2024-01-26 18:38:34.643 31251-31267 BpBinder                com.jamesbayy.RNcameraBug            I  onLastStrongRef automatically unlinking death recipients: <uncached descriptor>
2024-01-26 18:38:35.623 31251-31251 HwDragEnhancementImpl   com.jamesbayy.RNcameraBug            D  handleTimerDrag: false
2024-01-26 18:38:35.623 31251-31251 HwDragEnhancementImpl   com.jamesbayy.RNcameraBug            D  handleTimerDrag: false
2024-01-26 18:38:35.632 31251-31251 HwDragEnhancementImpl   com.jamesbayy.RNcameraBug            D  Start long press for hw drag enhancement.
2024-01-26 18:38:35.640 31251-31251 WebViewDragEnhancement  com.jamesbayy.RNcameraBug            D  dragReset.
2024-01-26 18:38:35.640 31251-31251 WebViewDragEnhancement  com.jamesbayy.RNcameraBug            D  dragReset cacheSize = 0
2024-01-26 18:38:35.661 31251-31343 AudioManager            com.jamesbayy.RNcameraBug            V  querySoundEffectsEnabled...
2024-01-26 18:38:35.661 31251-31343 AudioManager            com.jamesbayy.RNcameraBug            I  querySoundEffectsEnabled fail id: 0
2024-01-26 18:38:35.664 31251-31251 CameraView              com.jamesbayy.RNcameraBug            D  Finding view 179...
2024-01-26 18:38:35.664 31251-31251 CameraView              com.jamesbayy.RNcameraBug            D  Found view 179!
2024-01-26 18:38:35.672 31251-31340 CamcorderProfile        com.jamesbayy.RNcameraBug            I  Closest matching CamcorderProfile: 8
2024-01-26 18:38:35.674 31251-31340 OMXClient               com.jamesbayy.RNcameraBug            I  IOmx service obtained
2024-01-26 18:38:35.676 31251-31340 RecordingSession        com.jamesbayy.RNcameraBug            I  Creating RecordingSession for /data/user/0/com.jamesbayy.RNcameraBug/cache/mrousavy6547712617399457134.mov
2024-01-26 18:38:35.687 31251-31340 RecordingSession        com.jamesbayy.RNcameraBug            I  Using H264 Video Codec at 50.0 Mbps..
2024-01-26 18:38:35.691 31251-31340 RecordingSession        com.jamesbayy.RNcameraBug            I  Created 3072 x 3072 @ 30 FPS H264 MOV LANDSCAPE_RIGHT 50.0 Mbps RecordingSession (without audio)!
2024-01-26 18:38:35.691 31251-31340 RecordingSession        com.jamesbayy.RNcameraBug            I  Starting RecordingSession..
2024-01-26 18:38:35.731 31251-31340 MediaRecorder           com.jamesbayy.RNcameraBug            I  start
2024-01-26 18:38:35.731 31251-31340 HwDeviceMangerFactory   com.jamesbayy.RNcameraBug            I  Create actual factory for mdm part.
2024-01-26 18:38:35.732 31251-31340 TransactionSponsor      com.jamesbayy.RNcameraBug            I  init device policy service.
2024-01-26 18:38:35.740 31251-31340 HwMediaRecorderImpl     com.jamesbayy.RNcameraBug            I  HwMediaRecorderImpl
2024-01-26 18:38:35.740 31251-31340 HwMediaRecorderImpl     com.jamesbayy.RNcameraBug            I  sendStateChangedIntent, state=3
2024-01-26 18:38:35.742 31251-31340 CameraSession           com.jamesbayy.RNcameraBug            I  Updating Video Outputs...
2024-01-26 18:38:35.742 31251-31340 VideoPipeline           com.jamesbayy.RNcameraBug            I  Removing FrameProcessor Output...
2024-01-26 18:38:35.742 31251-31340 VideoPipeline           com.jamesbayy.RNcameraBug            I  Setting 3072 x 3072 RecordingSession Output...
2024-01-26 18:38:35.775 31251-32489 VideoPipeline           com.jamesbayy.RNcameraBug            I  Rendering to RecordingSession..
2024-01-26 18:38:35.775 31251-32489 OpenGLRenderer          com.jamesbayy.RNcameraBug            I  Creating Window Surface...
2024-01-26 18:38:35.805 31251-32489 VideoPipeline           com.jamesbayy.RNcameraBug            I  Rendering to RecordingSession..
2024-01-26 18:38:35.845 31251-32489 VideoPipeline           com.jamesbayy.RNcameraBug            I  Rendering to RecordingSession..
2024-01-26 18:38:35.855 31251-31251 RecordingSession        com.jamesbayy.RNcameraBug            E  MediaRecorder Error: 268435556 (-1007)
2024-01-26 18:38:35.855 31251-31251 RecordingSession        com.jamesbayy.RNcameraBug            I  Stopping RecordingSession..
2024-01-26 18:38:35.855 31251-31251 MediaRecorder           com.jamesbayy.RNcameraBug            I  stop
2024-01-26 18:38:35.876 31251-31251 MediaRecorder           com.jamesbayy.RNcameraBug            E  stop failed: -1007
2024-01-26 18:38:35.877 31251-31251 AndroidRuntime          com.jamesbayy.RNcameraBug            D  Shutting down VM
2024-01-26 18:38:35.881 31251-31251 AndroidRuntime          com.jamesbayy.RNcameraBug            E  FATAL EXCEPTION: main
                                                                                                    Process: com.jamesbayy.RNcameraBug, PID: 31251
                                                                                                    java.lang.RuntimeException: stop failed.
                                                                                                        at android.media.MediaRecorder.native_stop(Native Method)
                                                                                                        at android.media.MediaRecorder.stop(MediaRecorder.java:2153)
                                                                                                        at com.mrousavy.camera.core.RecordingSession.stop(RecordingSession.kt:102)
                                                                                                        at com.mrousavy.camera.core.RecordingSession._init_$lambda$0(RecordingSession.kt:74)
                                                                                                        at com.mrousavy.camera.core.RecordingSession.$r8$lambda$enBPf4dA0r-MTevnd6ChW75ZCDg(Unknown Source:0)
                                                                                                        at com.mrousavy.camera.core.RecordingSession$$ExternalSyntheticLambda0.onError(Unknown Source:2)
                                                                                                        at android.media.MediaRecorder$EventHandler.handleMessage(MediaRecorder.java:1638)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:117)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                        at android.os.Looper.loop(Looper.java:293)
                                                                                                        at android.app.ActivityThread.loopProcess(ActivityThread.java:9934)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:9923)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1240)

Camera Device

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

Device

HUAWEI nova 9

VisionCamera Version

3.8.2

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

chege4179 commented 7 months ago

Hello @jamesbayy Did you find what was causing this error and how to fix it ? I have the same issue

jamesbayy commented 7 months ago

Hello @jamesbayy Did you find what was causing this error and how to fix it ? I have the same issue

haven't found a solution yet

mrousavy commented 7 months ago

hmm, maybe related: https://stackoverflow.com/a/16543157/5281431

mrousavy commented 7 months ago

Just to provide more insights on those logs:

18:38:35.691 RecordingSession        I  Starting RecordingSession..
18:38:35.731 MediaRecorder           I  start
18:38:35.731 HwDeviceMangerFactory   I  Create actual factory for mdm part.
18:38:35.732 TransactionSponsor      I  init device policy service.
18:38:35.740 HwMediaRecorderImpl     I  HwMediaRecorderImpl
18:38:35.740 HwMediaRecorderImpl     I  sendStateChangedIntent, state=3
18:38:35.742 CameraSession           I  Updating Video Outputs...
18:38:35.742 VideoPipeline           I  Removing FrameProcessor Output...
18:38:35.742 VideoPipeline           I  Setting 3072 x 3072 RecordingSession Output...
18:38:35.775 VideoPipeline           I  Rendering to RecordingSession..
18:38:35.775 OpenGLRenderer          I  Creating Window Surface...
18:38:35.805 VideoPipeline           I  Rendering to RecordingSession..
18:38:35.845 VideoPipeline           I  Rendering to RecordingSession..
18:38:35.855 RecordingSession        E  MediaRecorder Error: 268435556 (-1007)
18:38:35.855 RecordingSession        I  Stopping RecordingSession..
18:38:35.855 MediaRecorder           I  stop
18:38:35.876 MediaRecorder           E  stop failed: -1007
18:38:35.877 AndroidRuntime          D  Shutting down VM
18:38:35.881 AndroidRuntime          E  FATAL EXCEPTION: main

You start the reocrding, then immediately we get this error in the logs:

18:38:35.855 RecordingSession        E  MediaRecorder Error: 268435556 (-1007)

And it fails. The stop failed error is a bit misleading, the actual error is the one above.

MuhammadFaisal215 commented 7 months ago

@mrousavy I have the same issue. When i hit the startRecording function my app suddenly crashes. I have check and this issue came on android 11. When i use android 13 it works fine.

Is there any solution that i can run this package on android 10,11,12,13 and 14.

mrousavy commented 5 months ago

Hey! I just released a new V4 beta (v4.0.0-beta.7) where I fixed a bunch of issues! 💪🚀 Can you test that and see if that fixes the issue for you? 😅

yarn add react-native-vision-camera@beta

You might need to increase the compileSdk to the newest Android SDK (34) if you are behind.

mrousavy commented 5 months ago

If latest V4 fixes this bug, please consider 💖 sponsoring me on GitHub 💖 so I can keep maintaining this library, fixing bugs and building new features! :)

4765-dipankargiri commented 1 month ago

Hi any update on this I am facing this issue with version 3.9.1 and even 4.3.1, also it happens frequently on any device. compileSDK 34 react-native 0.71.14