Android:尝试录制视频时“启动失败-12”

时间:2013-01-29 07:36:56

标签: android video camera

我有一个活动,其中有一个按钮,按下时开始录制视频。当MediaRecorder.start();执行时,“启动失败”会发生异常。

camera.unlock();
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setOutputFile(filename);
mediaRecorder.setPreviewDisplay(mSurfaceView.getHolder().getSurface());

try
{
  mediaRecorder.prepare();
}
catch (Exception ex)
{
  ReleaseMediaRecorder();
  return false;
}
     

mediaRecorder.start();

清单:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />

logcat的

01-29 08:48:44.479: D/AudioRecord(799): set(): sampleRate 8000, channels 16, frameCount 4096
01-29 08:48:44.499: W/AudioHardwareMSM76XXA(799): rpc_snd_set_device(6, 1, 1)
01-29 08:48:44.519: I/QualcommCameraHardware(799): setRecordSize: preview dimensions: 176x144
01-29 08:48:44.519: I/QualcommCameraHardware(799): setRecordSize: video dimensions: 176x144
01-29 08:48:44.529: I/QualcommCameraHardware(799): Parameter Rolloff is not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): Parameter MCE is not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): Sharpness not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): Saturation not supported for this sensor
01-29 08:48:44.529: E/QualcommCameraHardware(799): Parameter Scenemode is not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): Contrast not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): Parameter AntiBanding is not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): setRedeyeReduction: setting Redeye Reduction value of disable
01-29 08:48:44.529: E/CAM_FD(799): config_proc_CAMERA_SET_REDEYE_REDUCTION: mode =0
01-29 08:48:44.529: E/CAM_FD(799): config_proc_CAMERA_SET_REDEYE_REDUCTION: FAILED
01-29 08:48:44.529: E/QualcommCameraHardware(799): native_set_parms failed: type 50 length 1 error Unknown error: 0
01-29 08:48:44.529: E/QualcommCameraHardware(799): Wavelet Denoise is not supported for this sensor
01-29 08:48:44.529: E/QualcommCameraHardware(799): FPS Range Values: 5000x31000
01-29 08:48:44.529: I/QualcommCameraHardware(799): Set fps is not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): set fps mode is not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): Auto Exposure not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): Exposure Compensation is not supported for this sensor
01-29 08:48:44.529: I/QualcommCameraHardware(799): setFlash: flash not supported
01-29 08:48:44.529: I/QualcommCameraHardware(799): Set Brightness not supported for this sensor
01-29 08:48:44.529: E/QualcommCameraHardware(799): Parameter ISO Value is not supported for this sensor
01-29 08:48:44.539: I/QualcommCameraHardware(799): setHighFrameRate: setting HFR value of off(1)
01-29 08:48:44.539: E/StagefrightRecorder(799): Failed to set frame rate to 20 fps. The actual frame rate is 31
01-29 08:48:44.559: E/VENC_OMX(799): OMX_VENC_MSG_HIGH Venc::203 OMX-ENC:-constructor
01-29 08:48:44.559: E/VENC_OMX(799): OMX_VENC_MSG_HIGH component_init::308 Initializing component OMX.qcom.video.encoder.h263
01-29 08:48:44.559: E/(799): OMX_VENC_MSG_HIGH VencMsgQ::133 Mutex created for VencMsgQ 0x80018
01-29 08:48:44.559: E/(799): OMX_VENC_MSG_HIGH VencMsgQ::142 Signal created for VencMsgQ 0x80028
01-29 08:48:44.559: E/VENC_ENC(799): VENC_MSG_HIGH venc_sys_up::4647 Bringing system up
01-29 08:48:44.559: E/VENC_ENC(799): VENC_MSG_HIGH venc_load::1118 Received command VENC_CMD_LOAD
01-29 08:48:44.569: E/VENC_ENC(799): VENC_MSG_HIGH venc_thread_fn::4575 thread entry
01-29 08:48:44.569: E/VENC_ENC(799): VENC_MSG_HIGH venci_process_command::4472 Processing command VENC_CMD_LOAD
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH process_DL_status::4453 got DL status for VENC_CMD_LOAD
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1544 OMX_IndexParamStandardComponentRole
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::888 OMX_IndexParamVideoPortFormat
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::888 OMX_IndexParamVideoPortFormat
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1262 OMX_IndexParamVideoPortFormat
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::908 OMX_IndexParamPortDefinition
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1293 OMX_IndexParamPortDefinition
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::888 OMX_IndexParamVideoPortFormat
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1262 OMX_IndexParamVideoPortFormat
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::908 OMX_IndexParamPortDefinition
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1293 OMX_IndexParamPortDefinition
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::1004 OMX_IndexParamVideoH263
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::1032 OMX_IndexParamVideoProfileLevelQuerySupported
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1449 OMX_IndexParamVideoH263
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::982 OMX_IndexParamVideoBitrate
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1362 OMX_IndexParamVideoBitrate
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::1105 OMX_IndexParamVideoErrorCorrection
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1428 OMX_IndexParamVideoErrorCorrection
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::908 OMX_IndexParamPortDefinition
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::1192 OMX_COMPONENT_CAPABILITY_TYPE_INDEX
01-29 08:48:44.569: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::1202 Supporting capability index in encoder node
01-29 08:48:44.859: D/AudioRecord(799): start
01-29 08:48:44.859: D/AudioFlinger(799): RecordThread::start
01-29 08:48:44.859: W/AudioHardwareMSM76XXA(799): rpc_snd_set_device(6, 1, 1)
01-29 08:48:45.169: D/MediaPlayer(799): seekTo 0 state 8
01-29 08:48:45.169: V/MediaPlayerService(799): getDuration
01-29 08:48:45.169: V/MediaPlayerService(799): [19] getDuration = 464
01-29 08:48:45.169: D/MediaPlayerService(799): [19] seekTo(0)
01-29 08:48:45.169: V/MediaPlayerService(799): [19] notify (0x924d0, 4, 0, 0)
01-29 08:48:45.169: D/MediaPlayer(799): start state 8
01-29 08:48:45.169: V/MediaPlayerService(799): [19] setLooping(0)
01-29 08:48:45.169: V/MediaPlayerService(799): [19] setVolume(1.000000, 1.000000)
01-29 08:48:45.169: V/AudioSink(799): setVolume(1.000000, 1.000000)
01-29 08:48:45.169: V/MediaPlayerService(799): [19] setAuxEffectSendLevel(0.000000)
01-29 08:48:45.169: V/AudioSink(799): setAuxEffectSendLevel(0.000000)
01-29 08:48:45.169: V/MediaPlayerService(799): [19] start
01-29 08:48:45.169: E/AwesomePlayer(799): AudioPlayer created, Non-LPA mode mime audio/vorbis duration 463938
01-29 08:48:45.169: D/AudioSink(799): flush
01-29 08:48:45.169: V/AudioSink(799): open(44100, 2, 1, 4, 27)
01-29 08:48:45.169: D/AudioTrack(799): Request AudioFlinger to create track
01-29 08:48:45.169: D/AudioFlinger(799): createTrack() lSessionId: 27
01-29 08:48:45.169: D/AudioFlinger(799): Track constructor name 4098, calling thread 799
01-29 08:48:45.169: V/AudioSink(799): setVolume
01-29 08:48:45.169: D/AudioSink(799): start
01-29 08:48:45.169: D/AudioTrack(799): start 0x796f0
01-29 08:48:45.179: D/AudioFlinger(799): start(4098), calling thread 799 session 27
01-29 08:48:45.179: E/AudioHardwareMSM76XXA(799): setVoiceVolume(0.200000)
01-29 08:48:45.179: E/AudioHardwareMSM76XXA(799): Setting in-call volume to 1 (available range is 1 to 6)
01-29 08:48:45.209: I/QualcommCameraHardware(799): startRecordingInternal: E
01-29 08:48:45.209: V/MediaPlayerService(799): [19] notify (0x924d0, 4, 0, 0)
01-29 08:48:45.209: E/VENC_OMX(799): OMX_VENC_MSG_HIGH get_parameter::908 OMX_IndexParamPortDefinition
01-29 08:48:45.209: E/VENC_OMX(799): OMX_VENC_MSG_HIGH set_parameter::1293 OMX_IndexParamPortDefinition
01-29 08:48:45.209: E/VENC_OMX(799): OMX_VENC_MSG_HIGH use_buffer::2091 client allocated input buffer for component 38016
01-29 08:48:45.209: E/VENC_OMX(799): OMX_VENC_MSG_ERROR use_buffer::2094 buffer size does not match our requirements: client ask for(460800) and we require (38016)
01-29 08:48:45.209: E/OMXNodeInstance(799): OMX_UseBuffer failed with error -2147479547 (0x80001005)
01-29 08:48:45.209: E/OMXCodec(799): allocate_buffer_with_backup failed
01-29 08:48:45.209: E/OMXCodec(799): Allocate Buffer failed - error = -2147483648
01-29 08:48:45.299: W/MPEG4Writer(799): notify Completion track:0
01-29 08:48:45.299: D/AudioRecord(799): stop
01-29 08:48:45.299: D/AudioFlinger(799): RecordThread::stop
01-29 08:48:45.309: V/MediaPlayerService(799): [19] notify (0x924d0, 2, 0, 0)
01-29 08:48:45.309: D/AudioSink(799): stop
01-29 08:48:45.309: D/AudioTrack(799): stop 0x796f0
01-29 08:48:45.309: D/AudioFlinger(799): stop(4098), calling thread 799
01-29 08:48:45.439: W/AudioHardwareMSM76XXA(799): rpc_snd_set_device(6, 1, 1)
01-29 08:48:45.449: E/MediaRecorder(574): start failed: -12

2 个答案:

答案 0 :(得分:1)

应在start()方法之后调用prepare()。 MediaRecorder的生命周期为here。如果在IllegalStateException

之前调用它,则start方法将抛出prepare().

答案 1 :(得分:0)

以下解决了问题:

mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));