Android MediaRecorder API keeps cropping the video bitrate

回眸只為那壹抹淺笑 提交于 2019-12-06 00:55:51

问题


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.


回答1:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/6725258/android-mediarecorder-api-keeps-cropping-the-video-bitrate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!