react-native-vision-camera
react-native-vision-camera copied to clipboard
🐛 Stop recording not working
What's happening?
I have been attempting to stop a video recording with the following logic seen below. But everytime I stop the recording the app crashes and I get a thread error.
Reproduceable Code
const takePhotoOrVideo = async (): Promise<void> => {
if (cameraRef.current) {
if (cameraState === "photo") {
await cameraRef.current
.takePhoto({ flash: flashEnabled })
.then((photo: any) => {
console.log(photo);
setPathOfMedia(photo.path);
// Convert photo to byte array
setDisplayMedia(true);
})
.catch((err: any) => {
enqueueMsg("error", `Failed to take photo: ${err}`);
});
} else if (cameraState === "video" && isCameraInRecordingState === false) {
// Set camera state to be in recording
setIsCameraInRecordingState(true);
await cameraRef.current.startRecording({
flash: flashEnabled,
onRecordingFinished: (video: VideoFile) => {
setPathOfMedia(video.path);
},
onRecordingError(error: CameraCaptureError) {
enqueueMsg("error", `Failed to record video: ${error}`);
},
});
} else if (cameraState === "video" && isCameraInRecordingState === true) {
setIsCameraInRecordingState(false);
await cameraRef.current.stopRecording();
setDisplayMedia(true);
}
}
};
Relevant log output
Thread 27: "*** -[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration"
Camera Device
{
"supportsLowLightBoost":false,
"id":"com.apple.avfoundation.avcapturedevice.built-in_video:0",
"position":"back",
"maxZoom":16,
"hardwareLevel":"full",
"supportsFocus":true,
"supportsRawCapture":false,
"neutralZoom":1,
"physicalDevices":[
"wide-angle-camera"
],
"sensorOrientation":"landscape-right",
"name":"Back Camera",
"hasFlash":true,
"minZoom":1,
"hasTorch":true,
"isMultiCam":false
}
Device
Ipad Pro (16.6)
VisionCamera Version
3.6.4
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
- [ ] I am using Expo
- [X] I have enabled Frame Processors (react-native-worklets-core)
- [X] I have read the Troubleshooting Guide
- [X] I agree to follow this project's Code of Conduct
- [X] I searched for similar issues in this repository and found none.
Downgrading vision camera to 3.2.2 seemed to solve the problem.
As I always say on every single issue: ~~Please~~ share the full logs.
Hey @mrousavy, please see if it helps:
VisionCamera.startRecording(options:onVideoRecorded:onError:): Starting Video recording...
VisionCamera.startRecording(options:onVideoRecorded:onError:): File path: /private/var/mobile/Containers/Data/Application/0C851915-C0A8-485C-9DF7-DBAA32F8EEC6/tmp/ReactNative/28C32550-D59F-49AF-A0B3-5CD6F344CDE1.mov
VisionCamera.startRecording(options:onVideoRecorded:onError:): Recommended Video Settings: ["AVVideoCodecKey": hvc1, "AVVideoWidthKey": 1080, "AVVideoCompressionPropertiesKey": {
AllowFrameReordering = 1;
AllowOpenGOP = 1;
AverageBitRate = 7651584;
ExpectedFrameRate = 30;
MaxAllowedFrameQP = 41;
MaxKeyFrameIntervalDuration = 1;
MinAllowedFrameQP = 15;
MinimizeMemoryUsage = 1;
Priority = 80;
ProfileLevel = "HEVC_Main_AutoLevel";
RealTime = 1;
RelaxAverageBitRateTarget = 1;
}, "AVVideoHeightKey": 1920]
VisionCamera.initializeVideoWriter(withSettings:pixelFormat:): Initialized Video AssetWriter.
VisionCamera.startAssetWriter(): Starting Asset Writer(s)...
<0x104911b00> Gesture: System gesture gate timed out.
VisionCamera.appendBuffer(_:type:timestamp:): Started RecordingSession at 142647.371578666 seconds.
VisionCamera.finish(): Finishing Recording with AssetWriter status "writing"...
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration'
*** First throw call stack:
(0x194e625e0 0x18d197c00 0x1b111f31c 0x100e11164 0x100e1ec80 0x1008610d0 0x104408f50 0x10440ab34 0x10441298c 0x104413728 0x1044205f8 0x10441fc2c 0x1fdf5e964 0x1fdf5ea04)
VisionCamera.startRecording(options:onVideoRecorded:onError:): RecordingSession finished with status completed.
VisionCamera.deactivateAudioSession(): Deactivating Audio Session...
{ path: 'file:///private/var/mobile/Containers/Data/Application/0C851915-C0A8-485C-9DF7-DBAA32F8EEC6/tmp/ReactNative/28C32550-D59F-49AF-A0B3-5CD6F344CDE1.mov',
duration: 7.099456709 }
libc++abi: terminating due to uncaught exception of type NSException
Let me know if you prefer that I open a new issue.
Thanks for the awesome lib and all the efforts put into it!
As I always say on every single issue: ~Please~ share the full logs.
What other logs are you referring to? I have provided you with the log output I got when the application crashed.
hey @josh-thompson13 he is talking about the "full" logs which is the trace from xcode you only share the line that you think is relevant there's some breadcrumbs left at specific points that logs information to help debugging this if you only share the error line this is irrelevant at all
Thanks @robsonbbs ! 👍
Will take a look when I have some free time.
@mrousavy Thank you very much. I found the cause of the #2172 . the logs:
Maybe this will help you. @josh-thompson13
@mrousavy Thank you very much. I found the cause of the #2172 . the logs:
Maybe this will help you. @josh-thompson13
Thanks will check it out!
Hey - I think I fixed this in the latest version of VisionCamera. :)
i have the same issue with the latest version, but i just have that problem on the first time to stop the camera after install, after the first crash the app works fine. do you have some idea? :(
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration' *** First throw call stack: (0x1985fe418 0x195965e88 0x1b6f56d5c 0x102f03460 0x102f12770 0x1027b54dc 0x1074a0ab0 0x1074a279c 0x1074aa668 0x1074ab3e0 0x1074b8640 0x1074b7c50 0x21f2e1c7c 0x21f2de488) 'Handle error native >', '*** -[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration\n(\n "4 libc++abi.dylib 0x000000021f20887c 20F3F597-0DBD-3E4F-8D43-3C379861E4BC + 75900",\n "5 libc++abi.dylib 0x000000021f208820 _ZSt9terminatev + 108",\n "6 libdispatch.dylib 0x00000001074a27b0 _dispatch_client_callout + 40",\n "7 libdispatch.dylib 0x00000001074aa668 _dispatch_lane_serial_drain + 828",\n "8 libdispatch.dylib 0x00000001074ab3e0 _dispatch_lane_invoke + 408"\n)'
I'd need full logs for that. That's why issue templates require full logs.
Sorry for question, how i get the full logs?
@flexingCode hey. I had the same issue.
Do you have a reproducible code at hand?
My problem was that
(1) I set <Camera audio={true} />
even though I didn't have the mic permission yet.
(2) Asked the user when he wanted to record a video for his mic permission and then started recording.
I fixed the problem in the following way:
<Camera audio={hasMicPermission} />
When the user wants to record a video, I still ask him to grant his mic permission. After his decision I return from the method and the user needs to click again on "record video".