react-native-vision-camera: đ `CameraDevice` contains formats that are not supported by `CamcorderProfile`
Whatâs happening?
When the video resolution is too high, recording does not work unless I use the H.265 codec.
Is it possible to know when to use the H.265 codec?
For example:
- working with h264/h265: {âautoFocusSystemâ: âcontrast-detectionâ, âfieldOfViewâ: 78.63484214515682, âmaxExposureâ: 8, âmaxFpsâ: 30, âmaxISOâ: 6400, âmaxZoomâ: 10, âminExposureâ: -8, âminFpsâ: 1, âminISOâ: 50, âphotoHeightâ: 2736, âphotoWidthâ: 3648, âpixelFormatsâ: [âyuvâ, ânativeâ], âsupportsDepthCaptureâ: true, âsupportsPhotoHdrâ: false, âsupportsVideoHdrâ: false, âvideoHeightâ: 2056, âvideoStabilizationModesâ: [âoffâ, âstandardâ, âcinematic-extendedâ], âvideoWidthâ: 3648}
- not working with h264 (/ working with h265): {âautoFocusSystemâ: âcontrast-detectionâ, âfieldOfViewâ: 78.63484214515682, âmaxExposureâ: 8, âmaxFpsâ: 30, âmaxISOâ: 6400, âmaxZoomâ: 10, âminExposureâ: -8, âminFpsâ: 1, âminISOâ: 50, âphotoHeightâ: 2736, âphotoWidthâ: 3648, âpixelFormatsâ: [âyuvâ, ânativeâ], âsupportsDepthCaptureâ: true, âsupportsPhotoHdrâ: false, âsupportsVideoHdrâ: false, âvideoHeightâ: 2736, âvideoStabilizationModesâ: [âoffâ, âstandardâ, âcinematic-extendedâ], âvideoWidthâ: 3648}
Reproduceable Code
const devices = Camera.getAvailableCameraDevices();
const device = devices.find((d) => d.position === 'back');
if (!device) {
return;
}
const format = getCameraFormat(device, [
{ videoResolution: 'max' },
]);
// ...
return (
<View style={s.container}>
<Camera
ref={this.cameraRef}
style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}
device={device}
format={format}
isActive={true}
video={true}
audio={true}
resizeMode='contain'
/>
</View>
);
Relevant log output
{"cause": {"message": "prepare failed.", "stacktrace": "java.io.IOException: prepare failed.
at android.media.MediaRecorder._prepare(Native Method)
at android.media.MediaRecorder.prepare(MediaRecorder.java:1107)
at com.mrousavy.camera.core.RecordingSession.start(RecordingSession.kt:91)
at com.mrousavy.camera.core.CameraSession.startRecording(CameraSession.kt:546)
at com.mrousavy.camera.CameraView_RecordVideoKt.startRecording(CameraView+RecordVideo.kt:56)
at com.mrousavy.camera.CameraViewModule$startRecording$1.invokeSuspend(CameraViewModule.kt:90)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
"}, "code": "capture/unknown", "message": "An unknown error occurred while trying to start a video recording! prepare failed.", "userInfo": null}
Camera Device
{
"sensorOrientation": "landscape-right",
"hardwareLevel": "limited",
"maxZoom": 10,
"minZoom": 1,
"supportsLowLightBoost": false,
"neutralZoom": 1,
"physicalDevices": [
"wide-angle-camera",
"ultra-wide-angle-camera",
"telephoto-camera"
],
"supportsFocus": true,
"supportsRawCapture": false,
"isMultiCam": true,
"name": "BACK (0)",
"hasFlash": true,
"hasTorch": true,
"position": "back",
"id": "0"
}
Device
HUAWEI P30 (ELE-L29) with Android 10
VisionCamera Version
3.6.10
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
- I have enabled Frame Processors (react-native-worklets-core)
- I have read the Troubleshooting Guide
- I agree to follow this projectâs Code of Conduct
- I searched for similar issues in this repository and found none.
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 31 (10 by maintainers)
wtf? lol
Itâs always the same - someone creates an issue, wants it fixed âasapâ because it hurts their business, then someone posts a local patch in the comments, and the issue goes stale. If you use open-source you are using something someone in the community has put hundreds or thousands of hours blood and sweat into, and then offered it to the public/you for free. To keep that project alive and working for the future you can either sponsor/support the devs/maintainers, or contribute back in some way shape or form - this wouldâve been an ideal example.
I have other priorities too than to help other people fix issues for their business.
lmao, I simply said âWouldâve been great âŚâ. If you get hurt over such a suggestion thatâs not my fault.
Doesnât matter anyways, but I think the PR wouldâve taken 2 minutes longer than writing that comment. I understand that time is valuable, and I understand that you are not required to create a PR, but still - it wouldâve been great.
Anyways, issue is now resolved since that PR is merged, thatâs all that matters.
Wow, youâre so fast! đ
I just tested. Unfortunately, I encountered another error.
This is due to the âqualityâ used (returned by findClosestCamcorderProfileQuality). In my case, it returns CamcorderProfile.QUALITY_4KDCI, and my phone only supports up to CamcorderProfile.QUALITY_2160P.
If I set it to CamcorderProfile.QUALITY_2160P, it works đ and the bitrate is correct! (âCreated 3648 x 2736 @ 30 FPS H264 MOV LANDSCAPE_RIGHT 40.0 Mbps RecordingSession (with audio)!â)
Ohh, interesting! Iâll try to fix the
getDefaultBitRate()
method by usingCamcorderProfile
instead of computing it on my own then!