MediaRecorder.setVideoSize()导致MediaRecorder.start()的RuntimeException(启动失败)

时间:2014-05-23 18:43:58

标签: java android mediarecorder

当我尝试为MediaRecorder设置视频大小时,我在start方法中得到一个RuntimeException。

mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
if (isVideo)
    mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
if (isVideo) {
    mRecorder.setVideoSize(480, 360); // Works fine when this is removed
    mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
}

mRecorder.setOutputFile(newFilePath);

if (isVideo)
    mRecorder.setPreviewDisplay(surfaceHolder.getSurface());

mRecorder.prepare();    // Prepare recorder
mRecorder.start();      // Start recording

2 个答案:

答案 0 :(得分:3)

在我的案例中,我发现这是最优雅的解决方案:

CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);

答案 1 :(得分:2)

使用getSupportedVideoSizes() on Camera.Parameters获取支持的视频尺寸。摄像机经常无法随意缩放图像,大概是出于性能原因。