问题描述
我试图建立一个应用程序,该应用程序在开始视频录制之前尝试自动对焦相机.直接使用MediaRecorder不会自动对焦相机.为此,我正在使用Camera并使用回调我可以自动对焦.但为MediaRecorder提供这个实例给了我很多问题.以下是使用用于录制的代码
public boolean startRecording() { try { mCamera.unlock(); mediaRecorder = new MediaRecorder(); mediaRecorder.setCamera(mCamera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); CamcorderProfile profile = CamcorderProfile .get(CamcorderProfile.QUALITY_LOW); mediaRecorder.setProfile(profile); mediaRecorder.setMaxDuration(maxDurationInMs); File file = new File(outputFile); if (file.exists()) file.delete(); file = new File(outputFile); try { file.createNewFile(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Log.e("Deepak", "*** first catch ***"); } mediaRecorder.setOutputFile(outputFile); mediaRecorder.setPreviewDisplay(mHolder.getSurface()); mediaRecorder.setMaxFileSize(maxFileSizeInBytes); mediaRecorder.prepare(); mediaRecorder.start(); return true; } catch (IllegalStateException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); return false; } catch (IOException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); return false; } }
相机属性如下:
Camera.Parameters parameters = mCamera.getParameters(); List<Size> sizeList = parameters.getSupportedPreviewSizes(); parameters.setPreviewFormat(ImageFormat.JPEG); parameters .setPreviewSize(sizeList.get(0).width, sizeList.get(0).height); mCamera.setParameters(parameters); mCamera.startPreview();
所有这些都给我以下错误消息:
11-22 16:51:25.314: DEBUG/Preview(4052): !!!!!!!!!!111Starting recording!!!!!!!!!!!!!! 11-22 16:51:25.334: ERROR/audio_input(59): unsupported parameter: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value 11-22 16:51:25.334: ERROR/audio_input(59): VerifyAndSetParameter failed 11-22 16:51:25.334: ERROR/CameraInput(59): Unsupported parameter(x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value) 11-22 16:51:25.334: ERROR/CameraInput(59): VerifiyAndSetParameter failed on parameter #0 11-22 16:51:25.344: DEBUG/AuthorDriver(59): setParamVideoEncodingBitrate() 256000 11-22 16:51:25.384: INFO/MediaRecorderJNI(4052): prepare: surface=0x222968 (id=1) 11-22 16:51:25.394: ERROR/PVOMXEncNode(59): PVMFOMXEncNode-Video_M4V::DoPrepare(): Got Component OMX.qcom.video.encoder.mpeg4 handle 11-22 16:51:25.394: WARN/CameraInput(59): refCount 0 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR update_param_port_def::1643 Frame rate is for input port (refer to OMX IL spec) 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR get_parameter::952 unsupported index 0x700000b 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR set_parameter::2720 unsupported index 0x700000b 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR translate_profile::1015 unsupported profile 11-22 16:51:25.394: ERROR/VENC_ENC(59): Bitrate 256000 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR get_parameter::952 unsupported index 0x6000005 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR set_parameter::2720 unsupported index 0x6000005 11-22 16:51:25.394: ERROR/PVOMXEncNode(59): PVMFOMXEncNode-Audio_AMRNB::DoPrepare(): Got Component OMX.PV.amrencnb handle 11-22 16:51:25.394: DEBUG/CameraInput(59): Intended mFrameWidth=176, mFrameHeight=144 11-22 16:51:25.404: DEBUG/CameraInput(59): Actual mFrameWidth=176, mFrameHeight=144 11-22 16:51:25.404: ERROR/VENC_ENC(59): VENC_ERROR ven_translate_config::428 Invalid mp4 configuration 11-22 16:51:25.424: INFO/AudioHardwareQSD(59): Routing audio to Speakerphone 11-22 16:51:25.424: DEBUG/AudioHardwareQSD(59): Switching audio device to 11-22 16:51:25.424: DEBUG/AudioHardwareQSD(59): Speakerphone 11-22 16:51:25.454: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.494: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.534: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.554: INFO/AudioHardwareQSD(59): AudioHardware PCM record is going to standby. 11-22 16:51:25.554: INFO/AudioHardwareQSD(59): Routing audio to Speakerphone 11-22 16:51:25.564: INFO/AudioHardwareQSD(59): do input routing device 800000 11-22 16:51:25.564: INFO/AudioHardwareQSD(59): Routing audio to Speakerphone with back mic 11-22 16:51:25.564: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.574: WARN/AudioFlinger(59): write blocked for 143 msecs, 52 delayed writes, thread 0xd7a8 11-22 16:51:25.604: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.644: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.684: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.754: DEBUG/AudioHardwareQSD(59): Switching audio device to 11-22 16:51:25.754: DEBUG/AudioHardwareQSD(59): Speakerphone 11-22 16:51:25.764: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.814: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.844: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.884: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.924: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.964: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:26.004: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:26.044: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:28.824: INFO/AudioHardwareQSD(59): AudioHardware pcm playback is going to standby. 11-22 16:51:31.324: DEBUG/Preview(4052): !!!!!!!!!!Stoping recording!!!!!!!!!!!!!!
这在指定位置创建一个文件,这是完全遮挡的,只有一束绿色水平线.
放置所有权限.使用Android 2.2.尝试了将确切的代码为这个但仍然有类似的VENC_ERROR
推荐答案
您需要在解锁相机之前停止预览
mCamera.stopPreview(); mCamera.unlock();
问题描述
Im trying to build an app which tries to auto focus the camera before starting the video recording. Directly using MediaRecorder does not auto focus the camera. For that i am Using Camera and using the callback I can autofocus it. But providing this instance to the MediaRecorder gives me a lot of issues. Following is the code im using for recording
public boolean startRecording() { try { mCamera.unlock(); mediaRecorder = new MediaRecorder(); mediaRecorder.setCamera(mCamera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); CamcorderProfile profile = CamcorderProfile .get(CamcorderProfile.QUALITY_LOW); mediaRecorder.setProfile(profile); mediaRecorder.setMaxDuration(maxDurationInMs); File file = new File(outputFile); if (file.exists()) file.delete(); file = new File(outputFile); try { file.createNewFile(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Log.e("Deepak", "*** first catch ***"); } mediaRecorder.setOutputFile(outputFile); mediaRecorder.setPreviewDisplay(mHolder.getSurface()); mediaRecorder.setMaxFileSize(maxFileSizeInBytes); mediaRecorder.prepare(); mediaRecorder.start(); return true; } catch (IllegalStateException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); return false; } catch (IOException e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); return false; } }
The Camera attributes are as follows:
Camera.Parameters parameters = mCamera.getParameters(); List<Size> sizeList = parameters.getSupportedPreviewSizes(); parameters.setPreviewFormat(ImageFormat.JPEG); parameters .setPreviewSize(sizeList.get(0).width, sizeList.get(0).height); mCamera.setParameters(parameters); mCamera.startPreview();
All this is giving me the following error message:
11-22 16:51:25.314: DEBUG/Preview(4052): !!!!!!!!!!111Starting recording!!!!!!!!!!!!!! 11-22 16:51:25.334: ERROR/audio_input(59): unsupported parameter: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value 11-22 16:51:25.334: ERROR/audio_input(59): VerifyAndSetParameter failed 11-22 16:51:25.334: ERROR/CameraInput(59): Unsupported parameter(x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value) 11-22 16:51:25.334: ERROR/CameraInput(59): VerifiyAndSetParameter failed on parameter #0 11-22 16:51:25.344: DEBUG/AuthorDriver(59): setParamVideoEncodingBitrate() 256000 11-22 16:51:25.384: INFO/MediaRecorderJNI(4052): prepare: surface=0x222968 (id=1) 11-22 16:51:25.394: ERROR/PVOMXEncNode(59): PVMFOMXEncNode-Video_M4V::DoPrepare(): Got Component OMX.qcom.video.encoder.mpeg4 handle 11-22 16:51:25.394: WARN/CameraInput(59): refCount 0 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR update_param_port_def::1643 Frame rate is for input port (refer to OMX IL spec) 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR get_parameter::952 unsupported index 0x700000b 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR set_parameter::2720 unsupported index 0x700000b 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR translate_profile::1015 unsupported profile 11-22 16:51:25.394: ERROR/VENC_ENC(59): Bitrate 256000 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR get_parameter::952 unsupported index 0x6000005 11-22 16:51:25.394: ERROR/VENC_ENC(59): VENC_ERROR set_parameter::2720 unsupported index 0x6000005 11-22 16:51:25.394: ERROR/PVOMXEncNode(59): PVMFOMXEncNode-Audio_AMRNB::DoPrepare(): Got Component OMX.PV.amrencnb handle 11-22 16:51:25.394: DEBUG/CameraInput(59): Intended mFrameWidth=176, mFrameHeight=144 11-22 16:51:25.404: DEBUG/CameraInput(59): Actual mFrameWidth=176, mFrameHeight=144 11-22 16:51:25.404: ERROR/VENC_ENC(59): VENC_ERROR ven_translate_config::428 Invalid mp4 configuration 11-22 16:51:25.424: INFO/AudioHardwareQSD(59): Routing audio to Speakerphone 11-22 16:51:25.424: DEBUG/AudioHardwareQSD(59): Switching audio device to 11-22 16:51:25.424: DEBUG/AudioHardwareQSD(59): Speakerphone 11-22 16:51:25.454: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.494: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.534: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.554: INFO/AudioHardwareQSD(59): AudioHardware PCM record is going to standby. 11-22 16:51:25.554: INFO/AudioHardwareQSD(59): Routing audio to Speakerphone 11-22 16:51:25.564: INFO/AudioHardwareQSD(59): do input routing device 800000 11-22 16:51:25.564: INFO/AudioHardwareQSD(59): Routing audio to Speakerphone with back mic 11-22 16:51:25.564: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.574: WARN/AudioFlinger(59): write blocked for 143 msecs, 52 delayed writes, thread 0xd7a8 11-22 16:51:25.604: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.644: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.684: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.754: DEBUG/AudioHardwareQSD(59): Switching audio device to 11-22 16:51:25.754: DEBUG/AudioHardwareQSD(59): Speakerphone 11-22 16:51:25.764: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.814: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.844: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.884: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.924: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:25.964: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:26.004: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:26.044: ERROR/CameraInput(59): Recording is not ready (iPeer 0x3bc14 iState 2 iWriteState 1 iClockState 0), frame dropped 11-22 16:51:28.824: INFO/AudioHardwareQSD(59): AudioHardware pcm playback is going to standby. 11-22 16:51:31.324: DEBUG/Preview(4052): !!!!!!!!!!Stoping recording!!!!!!!!!!!!!!
This creates a file on the specified location which is totally obscured, just a bunch of green horizontal lines.
All permission are placed. Using Android 2.2. Tried the exact code as this but still got similar VENC_ERROR
推荐答案
You need to stop the preview prior to unlocking the camera
mCamera.stopPreview(); mCamera.unlock();