views:

94

answers:

2

On a Nexus One (for example), the camera application is able to capture H.264 video at 720x480 (the "High" quality setting). However, when using the MediaRecorder API, it always seems to capture at a fixed frame size of 320x240.

I would expect the setVideoSize() method to control the frame size (as in the prepare fragment below), but it appears to have no effect (using Froyo 2.2 Android SDK).

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setOutputFile(PATH_TO_FILE);
recorder.setVideoSize(720,480);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();

Discussions on the android developers list seem to indicate this is a long standing issue. Can anyone advise how the frame size can be controlled, or if it is possible at all with the current API?

A: 

recorder.setVideoSize seems to be a broken API and doesn't seem to work. But you can use the "high quality" preset that will set the video output format, encoders, size and frame rate for you. I'm assuming this is because these settings are hardware accelerated?

On my Nexus one this worked:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setOutputFile(PATH_TO_FILE);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
dzeikei
+1  A: 

The order is important. Try calling setVideoSize before setVideoEncoder:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setVideoSize(720,480);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setOutputFile(PATH_TO_FILE);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
vanevery