是否有可能在没有音频源的情况下使用CamcorderProfile?
我的代码:是否有可能在没有音频源的情况下使用CamcorderProfile?
mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(camera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
CamcorderProfile profile = CamcorderProfile.get(QUALITY_LOW);
mediaRecorder.setProfile(profile);
它的工作原理。 但我只需要录制视频。
如果我不使用mediaRecorder.setAudioSource(),则mediaRecorder.setProfile()会失败,并显示IllegalStateException。
有什么想法?
公共无效setProfile(CamcorderProfile轮廓)
自:API等级8使用来自CamcorderProfile对象的设置 为 记录。在视频和音频 源设置为之前以及在 setOutputFile()之前,此方法应为 ,称为。
从Android - CamcorderProfile docs
每个配置文件指定以下 组参数:
- 文件输出格式
- 视频编解码器格式
- 视频比特每秒比特率
- Vid EO帧速率在每秒
- 视频帧的宽度和高度的帧,
- 音频编解码器格式的音频比特率的比特每秒
- 音频采样率,用于记录音频通道
- 数目。
我说你可以读取所需CamcorderProfile相关视频相关的设置,并设置他们自己的明确。
的方法setProfile(MediaRecorder的)
我们可以看到,如果:
profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW //1002
&&
profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA //1007
不会有setAudio *() 因此,在你的代码,你可以手动设置profile.quality=[any int from 1002 to 1007]
之前setProfile()
。 它会工作,我试过了。
心中已经找到了正确的答案:
if (getIsMuteShooting()) { // with out audio
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setVideoFrameRate(profile.videoFrameRate);
mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mRecorder.setVideoEncoder(profile.videoCodec);
} else {
mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setVideoFrameRate(profile.videoFrameRate);
mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mRecorder.setAudioEncodingBitRate(profile.audioBitRate);
mRecorder.setAudioChannels(profile.audioChannels);
mRecorder.setAudioSamplingRate(profile.audioSampleRate);
mRecorder.setVideoEncoder(profile.videoCodec);
mRecorder.setAudioEncoder(profile.audioCodec);
}
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
mediaRecorder.setOutputFormat(profile.fileFormat);
mediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mediaRecorder.setVideoEncoder(profile.videoCodec);
请在回答中添加一些说明,以便它对OP有帮助,其他 – 2015-12-02 15:22:08
这确实应该是适用于CamcorderProfiles任何剪裁;例如如果您不想使用默认的视频比特率但不是一个(不是所有的配置文件参数都可以更改,有的会四舍五入到最接近的可能值) – ysmartin 2014-05-08 21:37:41