mrousavy / react-native-vision-camera

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

🐛 After `pauseRecording()`, `stopRecording()` takes 4 seconds longer than if not paused #2732

Open Mikewa33 opened 1 month ago

Mikewa33 commented 1 month ago

What's happening?

I logged every appendBuffer call at all if cases that are commented. While the video is recording we get a ton of

2024-04-09 16:05:17.089435-0400 Hetal[11959:1948327] [native] VisionCamera.appendBuffer(_:clock:type:): 3: Last Written Timestamp Buffer Optional(__C.CMTime(value: 204422346222041, timescale: 1000000000, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0))

But our design calls for a pause function before saving. So we pause the video before calling stopRecording. When paused the buffer logs don't write cause the camera is paused. We have a button for the user to save and that calls stopRecording(). When that is called then these logs happen

2024-04-09 16:05:21.210329-0400 Hetal[11959:1948456] [native] VisionCamera.stop(clock:): Requesting stop at 204426.518807333 seconds for AssetWriter with status "writing"...
2024-04-09 16:05:25.410054-0400 Hetal[11959:1948327] [native] VisionCamera.stop(clock:): Waited 4.0 seconds but no late Frames came in, aborting capture...

On the react side the camera init looks like this

<Camera
        style={StyleSheet.absoluteFill}
        ref={cameraRef}
        device={device}
        isActive={true}
        format={format}
        video={true}
        fps={format.maxFps}
        enableZoomGesture={true}
      />

When the user pauses the recording we call cameraRef.current.pauseRecording();

We then have buttons to save or retake the video. On save we call cameraRef.current.stopRecording();

I think because it is in a pause state when we call stop no buffers are being called and that prevent finish() from happening as it normally would

Reproduceable Code

cameraRef.current.pauseRecording();
cameraRef.current.stopRecording();

Relevant log output

2024-04-09 16:05:17.089435-0400 Hetal[11959:1948327] [native] VisionCamera.appendBuffer(_:clock:type:): 3: Last Written Timestamp Buffer Optional(__C.CMTime(value: 204422346222041, timescale: 1000000000, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0))
2024-04-09 16:05:21.210329-0400 Hetal[11959:1948456] [native] VisionCamera.stop(clock:): Requesting stop at 204426.518807333 seconds for AssetWriter with status "writing"...
2024-04-09 16:05:25.410054-0400 Hetal[11959:1948327] [native] VisionCamera.stop(clock:): Waited 4.0 seconds but no late Frames came in, aborting capture...

Camera Device

{
  "hardwareLevel": "full",
  "hasTorch": true,
  "formats": [],
  "isMultiCam": false,
  "sensorOrientation": "landscape-right",
  "maxExposure": 8,
  "supportsLowLightBoost": false,
  "minZoom": 1,
  "minExposure": -8,
  "hasFlash": true,
  "name": "Back Camera",
  "maxZoom": 123.75,
  "minFocusDistance": 10,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "neutralZoom": 1,
  "id": "com.apple.avfoundation.avcapturedevice.built-in_video:0",
  "position": "back"
}

Device

iPhone SE

VisionCamera Version

3.9.1

Can you reproduce this issue in the VisionCamera Example app?

No, I cannot reproduce the issue in the Example app

Additional information

mrousavy commented 1 month ago

yea, this is a bug.

thanhtungkhtn commented 3 weeks ago

Any update on this? facing similar issue

"react": "18.2.0",
"react-native": "0.74.1",
"react-native-vision-camera": "^4.0.3"
mrousavy commented 2 weeks ago

No update yet, if you want me to fix this for ya, contact me thru my agency or sponsor this issue.