Drazen Bjelovuk
Drazen Bjelovuk

Reputation: 5472

MediaRecorder.setVideoSize() causes RuntimeException (start failed) at MediaRecorder.start()

When I attempt to set the video size for my MediaRecorder, I get a RuntimeException at the start method.

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

Upvotes: 1

Views: 1059

Answers (2)

Drazen Bjelovuk
Drazen Bjelovuk

Reputation: 5472

Here's what I've found to be the most elegant solution in my case:

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

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1006584

Use getSupportedVideoSizes() on Camera.Parameters to get the supported video sizes. Cameras frequently cannot arbitrarily scale the image, presumably for performance reasons.

Upvotes: 2

Related Questions