I am building an Android app that records video using Camera X.
The probe in a Samsung A52 and it works correctly.
When running on a Galaxy Core A03 I get these errors:
E/Recorder: Unable to initialize video encoder.
androidx.camera.video.internal.encoder.InvalidConfigException: Encoder cannot created: null
at androidx.camera.video.internal.workaround.EncoderFinder.findEncoder(EncoderFinder.java:88)
at androidx.camera.video.internal.encoder.EncoderImpl.(EncoderImpl.java:214)
at androidx.camera.video.Recorder.setupVideo(Recorder.java:1294)
at androidx.camera.video.Recorder.initializeInternal(Recorder.java:998)
at androidx.camera.video.Recorder.lambda$onSurfaceRequested$0$androidx-camera-video-Recorder(Recorder.java:396)
at androidx.camera.video.Recorder$$ExternalSyntheticLambda16.run(Unknown Source:4)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:111)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:231)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:173)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7815)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1094)
Caused by: java.lang.NullPointerException
at android.media.MediaCodec.native_setup(Native Method)
at android.media.MediaCodec.(MediaCodec.java:1912)
at android.media.MediaCodec.createByCodecName(MediaCodec.java:1890)
at androidx.camera.video.internal.workaround.EncoderFinder.findEncoder(EncoderFinder.java:85)
at androidx.camera.video.internal.encoder.EncoderImpl.(EncoderImpl.java:214)
at androidx.camera.video.Recorder.setupVideo(Recorder.java:1294)
at androidx.camera.video.Recorder.initializeInternal(Recorder.java:998)
at androidx.camera.video.Recorder.lambda$onSurfaceRequested$0$androidx-camera-video-Recorder(Recorder.java:396)
at androidx.camera.video.Recorder$$ExternalSyntheticLambda16.run(Unknown Source:4)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:111)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:231)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:173)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7815)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1094)
D/Recorder: Transitioning Recorder internal state: INITIALIZING --> ERROR
D/PreviewView: Surface requested by Preview.
D/SurfaceViewImpl: Surface created.
D/SurfaceViewImpl: Surface changed. Size: 960x720
D/PreviewView: Preview transformation info updated. TransformationInfo{cropRect=Rect(0, 0 - 960, 720), rotationDegrees=90, targetRotation=0}
D/PreviewTransform: Transformation info set: TransformationInfo{cropRect=Rect(0, 0 - 960, 720), rotationDegrees=90, targetRotation=0} 960x720 false
D/SurfaceViewImpl: Surface set on Preview.
D/SyncCaptureSessionBase: [androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl#d97cfb7] getSurface...done
D/Camera2CameraImpl: {Camera#1dd1e08[id=0]} Posting surface closed
java.lang.Throwable
at androidx.camera.camera2.internal.Camera2CameraImpl.postSurfaceClosedError(Camera2CameraImpl.java:1174)
at androidx.camera.camera2.internal.Camera2CameraImpl$2.onFailure(Camera2CameraImpl.java:1116)
at androidx.camera.core.impl.utils.futures.Futures$CallbackListener.run(Futures.java:340)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:231)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:173)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
D/DeferrableSurface: surface closed, useCount=0 closed=true androidx.camera.core.SurfaceRequest$2#3051f61
D/DeferrableSurface: Surface terminated[total_surfaces=2, used_surfaces=0](androidx.camera.core.SurfaceRequest$2#3051f61}
D/DeferrableSurface: Surface created[total_surfaces=3, used_surfaces=0](androidx.camera.core.SurfaceRequest$2#8dfc68e}
D/Recorder: Surface is requested in state: ERROR, Current surface: 0
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mrkevin574.teteo, PID: 16045
java.lang.IllegalStateException: Surface was requested when the Recorder had encountered error androidx.camera.video.internal.ResourceCreationException: androidx.camera.video.internal.encoder.InvalidConfigException: Encoder cannot created: null
at androidx.camera.video.Recorder.onSurfaceRequested(Recorder.java:406)
at androidx.camera.video.VideoCapture.createPipeline(VideoCapture.java:416)
at androidx.camera.video.VideoCapture.resetPipeline(VideoCapture.java:482)
at androidx.camera.video.VideoCapture.lambda$createPipeline$0$androidx-camera-video-VideoCapture(VideoCapture.java:433)
at androidx.camera.video.VideoCapture$$ExternalSyntheticLambda0.onError(Unknown Source:10)
at androidx.camera.camera2.internal.Camera2CameraImpl.lambda$postSurfaceClosedError$14(Camera2CameraImpl.java:1175)
at androidx.camera.camera2.internal.Camera2CameraImpl$$ExternalSyntheticLambda7.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7815)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1094)
V/FA: Recording user engagement, ms: 3688
D/TransportRuntime.SQLiteEventStore: Storing event with priority=HIGHEST, name=FIREBASE_CRASHLYTICS_REPORT for destination cct
D/TransportRuntime.JobInfoScheduler: Scheduling upload for context TransportContext(cct, HIGHEST, MSRodHRwczovL2NyYXNobHl0aWNzcmVwb3J0cy1wYS5nb29nbGVhcGlzLmNvbS92MS9maXJlbG9nL2xlZ2FjeS9iYXRjaGxvZ1xBSXphU3lCcnBTWVQ0RkZMMDlyZUhKaTZIOUZZZGVpU25VVE92Mk0=) with jobId=-1451806366 in 1000ms(Backend next call timestamp 1649111614302). Attempt 1
I/Process: Sending signal. PID: 16045 SIG: 9
here the code of getVideoCapture():
private fun getVideoCapture() : VideoCapture<Recorder>{
val qualitySelector = QualitySelector.fromOrderedList(
listOf(Quality.UHD, Quality.FHD, Quality.HD, Quality.SD),
FallbackStrategy.lowerQualityOrHigherThan(Quality.SD)
)
val recorder = Recorder.Builder()
.setExecutor(ContextCompat.getMainExecutor(requireContext()))
.setQualitySelector(qualitySelector)
.build()
return VideoCapture.withOutput(recorder)
}
I have it exactly as the Android documentation tells me.
I'm also having the same error after learning about CameraX at the following link https://developer.android.com/codelabs/camerax-getting-started
I think it's true what Morrison Chang said, there is something problem with Low End Android devices.
So I downgraded the quality of the Recorder contained inside the startCamera() function from HIGHEST to SD or HD and it's work.
val recorder = Recorder.Builder()
//.setQualitySelector(QualitySelector.from(Quality.HIGHEST))
.setQualitySelector(QualitySelector.from(Quality.SD))//change to Quality.SD or Quality.HD
.build()
videoCapture = VideoCapture.withOutput(recorder)
I am implementing a CameraActivity using CameraX with the current latest version 1.1.0-beta01 / 1.1.0-beta02.
But even with sample code from github (CameraXbasic) it is not working on the most recent Emulators for API 31 and API 32.
Is there any way to get this work?
2022-03-11 12:51:07.393 18491-18556/com.android.example.cameraxbasic E/CameraCaptureSession: Session 0: Exception while stopping repeating:
android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): The camera device has encountered a serious error
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:2350)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1277)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:579)
at androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl.close(SynchronizedCaptureSessionBaseImpl.java:464)
at androidx.camera.camera2.internal.CaptureSession.release(CaptureSession.java:418)
at androidx.camera.camera2.internal.Camera2CameraImpl.releaseSession(Camera2CameraImpl.java:518)
at androidx.camera.camera2.internal.Camera2CameraImpl.resetCaptureSession(Camera2CameraImpl.java:1201)
at androidx.camera.camera2.internal.Camera2CameraImpl.closeCamera(Camera2CameraImpl.java:432)
at androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback.reopenCameraAfterError(Camera2CameraImpl.java:1665)
at androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback.handleErrorOnOpen(Camera2CameraImpl.java:1617)
at androidx.camera.camera2.internal.Camera2CameraImpl$StateCallback.onError(Camera2CameraImpl.java:1593)
at androidx.camera.camera2.internal.CameraDeviceStateCallbacks$ComboDeviceStateCallback.onError(CameraDeviceStateCallbacks.java:121)
at android.hardware.camera2.impl.CameraDeviceImpl.notifyError(CameraDeviceImpl.java:1748)
at android.hardware.camera2.impl.CameraDeviceImpl.$r8$lambda$KBQCqQRdhVVn7uHI9Xdha6OqnsU(Unknown Source:0)
at android.hardware.camera2.impl.CameraDeviceImpl$$ExternalSyntheticLambda0.accept(Unknown Source:8)
at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:281)
at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:204)
at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:97)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:111)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:231)
at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:173)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
I want to record a video in WebM format with Camera2 and MediaRecorder.
To do this, I'm using the Camera2Video sample code on Github. The sample shows the way to record in mp4 format, using back or front camera.
The MediaRecorder configuration is done in a single method:
/** Creates a [MediaRecorder] instance using the provided [Surface] as input */
private fun createRecorder(surface: Surface) = MediaRecorder().apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setVideoSource(MediaRecorder.VideoSource.SURFACE)
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
setOutputFile(outputFile.absolutePath)
setVideoEncodingBitRate(RECORDER_VIDEO_BITRATE)
if (args.fps > 0) setVideoFrameRate(args.fps)
setVideoSize(args.width, args.height)
setVideoEncoder(MediaRecorder.VideoEncoder.H264)
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
setInputSurface(surface)
}
And what I'm trying to do is to find a goof configuration to record in webm
private fun createRecorder(surface: Surface) = MediaRecorder().apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setVideoSource(MediaRecorder.VideoSource.SURFACE)
setOutputFormat(MediaRecorder.OutputFormat.WEBM)
setOutputFile(outputFile.absolutePath)
setVideoEncodingBitRate(RECORDER_VIDEO_BITRATE)
if (args.fps > 0) setVideoFrameRate(args.fps)
setVideoSize(args.width, args.height)
setVideoEncoder(MediaRecorder.VideoEncoder.VP8)
setAudioEncoder(MediaRecorder.AudioEncoder.VORBIS)
setInputSurface(surface)
}
But, doing this, I'm facing a crash:
2020-12-09 14:59:26.560 28899-28899/com.android.example.camera2.video W/CameraDevice-JV-0: Stream configuration failed due to: endConfigure:543: Camera 0: Unsupported set of inputs/outputs provided
2020-12-09 14:59:26.564 28899-28899/com.android.example.camera2.video E/CameraCaptureSession: Session 0: Failed to create capture session; configuration failed
2020-12-09 14:59:26.566 28899-28945/com.android.example.camera2.video E/CameraFragment: Camera 0 session configuration failed
java.lang.RuntimeException: Camera 0 session configuration failed
at com.example.android.camera2.video.fragments.CameraFragment$createCaptureSession$$inlined$suspendCoroutine$lambda$1.onConfigureFailed(CameraFragment.kt:375)
at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.lambda$onConfigureFailed$1(CallbackProxies.java:64)
at android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$gvbTsp9UPpKJAbdycdci_ZW5BeI.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.os.HandlerThread.run(HandlerThread.java:65)
2020-12-09 14:59:26.607 28899-28899/com.android.example.camera2.video E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.example.camera2.video, PID: 28899
java.lang.RuntimeException: Camera 0 session configuration failed
at com.example.android.camera2.video.fragments.CameraFragment$createCaptureSession$$inlined$suspendCoroutine$lambda$1.onConfigureFailed(CameraFragment.kt:375)
at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.lambda$onConfigureFailed$1(CallbackProxies.java:64)
at android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$gvbTsp9UPpKJAbdycdci_ZW5BeI.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.os.HandlerThread.run(HandlerThread.java:65)
The first line tells me there is a misconfiguration
Stream configuration failed due to: endConfigure:543: Camera 0: Unsupported set of inputs/outputs provided
I tried to comment lines about audio source too because I see that Vorbis Encoder is not supported with the same results.
How can I record a video in WebM format ?
I am using florent37:cameraFragment for custom camera. It working fine in lollipop but it is not working Nougat version. Please help me out. Thanks in advance
E/WVMExtractor: Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found
03-29 12:41:47.722 3773-3863/com.camerasample I/OMXClient: MuxOMX ctor
03-29 12:41:47.914 3773-3836/com.camerasample I/MediaRecorderJNI: prepare: surface=0x98162800
03-29 12:41:48.115 3773-3836/com.camerasample E/MediaRecorder: start failed: -2147483648
03-29 12:41:48.115 3773-3836/com.camerasample E/AndroidRuntime: FATAL EXCEPTION: BaseCameraManager
Process: com.camerasample, PID: 3773
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at com.github.florent37.camerafragment.internal.manager.impl.Camera1Manager$4.run(Camera1Manager.java:192)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
I'm using the google sample app camera2basic (https://github.com/googlesamples/android-Camera2Basic) , but it throws exception after performing the first picture capture. I see the camera is closed, but how to fix it properly? I expected the google sample to show the proper lifecycle.
Here is the exception:
07-06 10:26:00.296 8066-8110/com.example.android.camera2basic I/RequestQueue﹕ Repeating capture request set.
07-06 10:26:00.571 8066-8111/com.example.android.camera2basic V/RenderScript﹕ 0x9e643200 Launching thread(s), CPUs 8
07-06 10:26:19.656 8066-8078/com.example.android.camera2basic W/CameraBase﹕ mediaserver's remote binder Camera object died
07-06 10:26:19.661 8066-8083/com.example.android.camera2basic W/CameraBase﹕ Camera service died!
07-06 10:26:19.661 8066-8144/com.example.android.camera2basic E/Camera﹕ Error 100
07-06 10:26:19.661 8066-8144/com.example.android.camera2basic E/RequestThread-0﹕ Received error 100 from the Camera1 ErrorCallback
07-06 10:26:19.661 8066-8144/com.example.android.camera2basic I/CameraDeviceState﹕ Legacy camera service transitioning to state ERROR
07-06 10:26:22.671 8066-8166/com.example.android.camera2basic E/RequestThread-0﹕ Hit timeout for jpeg callback!
07-06 10:26:22.671 8066-8166/com.example.android.camera2basic W/RequestHolder﹕ Capture failed for request: 3
07-06 10:26:22.671 8066-8166/com.example.android.camera2basic I/CameraDeviceState﹕ Legacy camera service transitioning to state CAPTURING
07-06 10:26:22.671 8066-8166/com.example.android.camera2basic E/CameraDeviceState﹕ Cannot call capture while in state: 0
07-06 10:26:22.681 8066-8166/com.example.android.camera2basic E/RequestThread-0﹕ Received device exception:
java.lang.RuntimeException: getParameters failed (empty parameters)
at android.hardware.Camera.native_getParameters(Native Method)
at android.hardware.Camera.getParameters(Camera.java:1953)
at android.hardware.camera2.legacy.RequestThreadManager$5.handleMessage(RequestThreadManager.java:807)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:145)
at android.os.HandlerThread.run(HandlerThread.java:61)
07-06 10:26:22.781 8066-8066/com.example.android.camera2basic W/CameraCaptureSession﹕ Session 0: The camera device was already closed:
java.lang.IllegalStateException: CameraDevice was already closed
at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:1482)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:677)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:328)
at com.example.android.camera2basic.Camera2BasicFragment.closeCamera(Camera2BasicFragment.java:560)
at com.example.android.camera2basic.Camera2BasicFragment.onPause(Camera2BasicFragment.java:468)
at android.app.Fragment.performPause(Fragment.java:2318)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:954)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
at android.app.FragmentManagerImpl.dispatchPause(FragmentManager.java:1898)
at android.app.Activity.performPause(Activity.java:6366)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1308)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3647)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3620)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3595)
at android.app.ActivityThread.access$1100(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5834)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)