Android VCR: failed to get surface

Hi, I am trying to use the camera API v2 to record video using a Raspberry Pi 3 device that uses the Raspberry Pi camera module attached to it.

I am developing this using Android Things with Kotlin.

This is what my video recording code looks like.

override fun startRecording(videoCameraCallback: VideoCameraCallback) { val cameraIdList = cameraManager.cameraIdList cameraManager.openCamera(cameraIdList[0], cameraStateCalback, null) Log.d("JJJ", "start recording called") } var cameraStateCalback = object : CameraDevice.StateCallback() { override fun onOpened(camera: CameraDevice?) { if (camera != null) { Log.d("JJJ", "onOpened and will now create handler and capture session") //create handler thread val thread = HandlerThread("MyHandlerThread") thread.start() val handler = Handler(thread.looper) //create capture session val mediaRecorderSurface = setMediaOutputSurface() val surfaces = ArrayList<Surface>() surfaces.add(mediaRecorderSurface) captureRequest = camera.createCaptureRequest(TEMPLATE_RECORD).build() camera.createCaptureSession(surfaces, cameraCaptureSessionCallBack,handler) Log.d("JJJ", "Created thread handler and capture session") } } override fun onDisconnected(camera: CameraDevice?) { Log.d("JJJ", "on disconnected") } override fun onError(camera: CameraDevice?, error: Int) { Log.d("JJJ", "on error") } } var cameraCaptureSessionCallBack = object : CameraCaptureSession.StateCallback(){ override fun onConfigureFailed(session: CameraCaptureSession?) { Log.d("JJJ", "on configured failed") } override fun onConfigured(session: CameraCaptureSession?) { Log.d("JJJ", "start recording") mediaRecorder.start() } } private fun setMediaOutputSurface(): Surface { var file = File(context.filesDir.absolutePath) if(file.canWrite() && file.canRead()){ Log.d("JJJ", "File location is fine") } mediaRecorder = MediaRecorder() mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE) //changed this to surface from camera and it fixed the cant get surface error mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4) mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264) mediaRecorder.setVideoSize(600,600) // mediaRecorder.setVideoEncodingBitRate(10000000) // mediaRecorder.setVideoEncodingBitRate(512 * 1000) mediaRecorder.setOutputFile(context.filesDir.absolutePath + "/"+System.currentTimeMillis() + ".mp4") mediaRecorder.setVideoFrameRate(30) mediaRecorder.prepare() // mediaRecorder.start() return mediaRecorder.surface 

}

This is my strategy

  • Get a list of camera IDs using the camera manager.
  • Open the first camera from the list (there is only one camera attached
  • upon successful opening, create a handler thread
  • Create a mediaRecorder with all the necessary parameters (video source, frame rate, etc.).
  • Get surface object from mediaRecorder (where it doesn't work)
  • Create a surface capture request from a media player and previously created hanlder
  • upon successful setup, call mediaRecorder.start to start recording video.

The full stacktrace error I get is below:

  12-01 09:58:23.981 8776-8776/com.jr.survailancedropboxcam W/CameraDevice-JV-0: Stream configuration failed due to: endConfigure:372: Camera 0: Unsupported set of inputs/outputs provided 12-01 09:58:23.985 8776-8958/com.jr.survailancedropboxcam D/JJJ: on configured failed 12-01 09:58:23.985 8776-8776/com.jr.survailancedropboxcam E/CameraCaptureSession: Session 0: Failed to create capture session; configuration failed 

Thanks in advance

+7
android video kotlin camera android-things
source share
1 answer

With the latest version (AndroidThings DP 6) you can use the camera v2 API

https://android-developers.googleblog.com/2017/11/android-things-developer-preview-6.html

This should work: https://github.com/googlesamples/android-Camera2Basic

You need to make sure the flag is set to true in the manifest

 <activity ... android:hardwareAccelerated="true"> 

The Camera2Basic sample using the Camera2 API and TextureView now works on both NXP devices and Raspberry Pi (with the hardwareAccelerated flag set to true)

+1
source share

All Articles