开发者

How to change framerate when using MediaRecorder Class

开发者 https://www.devze.com 2023-02-19 00:57 出处:网络
I try to record video using MediaRecorder Class. However I find out that I failed to lower the framerate of the video stream.

I try to record video using MediaRecorder Class.

However I find out that I failed to lower the framerate of the video stream.

I'm using H.264 as my Video Encoder and AAC as my Audio Encoder(yes, it is supported in API LEVEL 10 and above, AKA Android 2.3.3+) The main source is as follows.

recorder = new MediaRecorder(); 
recorder.setPreviewDisplay(surfaceHolder.getSurface());
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//set the Output Format
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);  
//set the Video Size
recorder.setVideoSize(176,144);   
//set the Frame rate
recorder.setVideoFrameRate(15);

//Set the Video Encoder
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); 
//Set the Audio Encoder
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);          
recorder.setOutputFile(myRecAudioFile.getAbsolutePath());
recorder.prepare();
recorder.start();

However I got the debug info that:

03-22 22:39:41.120: WARN/StagefrightRecorder(662): Intended video encoding frame rate (15 fps) is too small and will be set to (27 fps)

Weird enough that I also got a error message 开发者_C百科that:

03-22 22:39:41.380: ERROR/VENC_ENC(662): Bitrate 192000

In the end, i got a mp4 file whose frame rate is nearly 28fps.


I also tried to use the lowest CamcorderProfile which is

recorder = new MediaRecorder(); 
recorder.setPreviewDisplay(surfaceHolder.getSurface());
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

//replacement
CamcorderProfile cpLow = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
recorder.setProfile(cpLow);

recorder.setOutputFile(myRecAudioFile.getAbsolutePath());
recorder.prepare();  
recorder.start();

and comment the verbose configuration of the recorder.

As the book Pro Android Media is Page 242 said I would got the video file with 15fps. However, I once again got a video file with about 27fps.


So how to lower the frame rate of a video? I'm building a live system so lowering bitrate got to be quite important to me. Thank you for your time!


I have just ran into this too. From the docs (bold mine):

On some devices that have auto-frame rate, this sets the maximum frame rate, not a constant frame rate. Actual frame rate will vary according to lighting conditions.

So it looks like you can't really control the frame rate. The number you set is used like a hint.


I just ran into this. If you want to reduce frame rate, we can use recorder.setCaptureRate(double); ie -> recorder.setCapturRate(12.00); I didn't get any changes while changing value in recorder.setVideoFrameRate(int).

while using recorder.setCaptureRate(double) it will record the video with the frame rate you mention. after recorder.release(), your video will play with the mentioned frame rate.

0

精彩评论

暂无评论...
验证码 换一张
取 消