Android录像机:未能获得表面

您好我正在尝试使用相机v2 API来记录video使用Raspberry Pi 3设备,使用树莓派相机模块附加到它。

我正在用Kotlin使用Android Things开发这个function。

这是我的video录制代码的样子。

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() 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 

}

这是我的策略

  1. 使用相机管理器获取相机ID的列表。
  2. 从列表中打开第一台相机(只有一台相机连接
  3. 当成功打开时,创建处理程序线程
  4. 创建mediaRecorder所有必要的参数(video源,帧率等
  5. mediaRecorder获取表面对象(失败的地方)
  6. 使用之前创建的媒体播放器和hanlder创建捕捉请求
  7. 如果配置成功,请调用mediaRecorder.start开始录制video。

我得到的完整stacktrace错误如下:

  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 

提前致谢

Kotlin language will be the best programming language for Android.