Lior Ohana
Lior Ohana

Reputation: 3527

Android MediaRecorder API keeps cropping the video bitrate

I'm working with the MediaRecorder API for a while, I thought all problems are behind me but I guess I was wrong.

I'm using the MediaRecorder API for recording video to a file. When I use the setProfile with high quality I get good quality but when I try to set the parameters manually (as in the code below) the quality is bad (since for some reason the bitrate is cropped). I want to get 720p with 1fps.

I keep getting the following warning: WARN/AuthorDriver(268): Video encoding bit rate is set to 480000 bps

The code I'm running:

m_MediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
m_MediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
m_MediaRecorder.setVideoSize(1280, 720);
m_MediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
m_MediaRecorder.setVideoFrameRate(1);
m_MediaRecorder.setVideoEncodingBitRate(8000000);

Any idea? Thanks a lot.

Upvotes: 6

Views: 6308

Answers (2)

Lior Ohana
Lior Ohana

Reputation: 3527

Found the solution...very weird however. Setting the bit-rate before setting the compression type somehow solved the problem. The only question is whether it is a bug in google's code or something else that I don't understand.

Original:

m_MediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
m_MediaRecorder.setVideoFrameRate(1);
m_MediaRecorder.setVideoEncodingBitRate(8000000);

Solution:

m_MediaRecorder.setVideoEncodingBitRate(8000000);
m_MediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
m_MediaRecorder.setVideoFrameRate(1);

Upvotes: 7

mportuesisf
mportuesisf

Reputation: 5617

The documentation for setVideoEncodingBitRate() says:

Sets the video encoding bit rate for recording. Call this method before prepare(). Prepare() may perform additional checks on the parameter to make sure whether the specified bit rate is applicable, and sometimes the passed bitRate will be clipped internally to ensure the video recording can proceed smoothly based on the capabilities of the platform.

Because the MediaRecorder API is dealing with a hardware encoding chip of some sort, that is different from device to device, it can't always give you every combination of codec, frame size, frame rate and encoding bitrate you ask for.

Your needs are somewhat unusual, in that you are trying to record at 1 fps. If you are developing your app for Honeycomb, there is a "time lapse" API for MediaRecorder along with an associated setCaptureRate() call that might be useful.

Upvotes: 2

Related Questions