如何使用MediaRecorder类何时改变帧率如何使用、MediaRecorder

2023-09-05 04:13:44 作者:自找的痛不敢喊痛

我尝试使用MediaRecorder类录制视频。

I try to record video using MediaRecorder Class.

不过,我发现,我没能降低视频流的帧率。

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

我用H.264作为我的视频恩codeR和AAC作为我的音频连接codeR(是的,它支持API级别10以上,AKA的Andr​​oid 2.3.3+) 的主要来源是如下

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 that:

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

在最后,我得到了一个MP4文件的帧速率几乎是28fps。

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

我也试过用最低的CamcorderProfile这是

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.

正如书​​中的临Android的媒体的是第242说我会得到与15fps的视频文件。但是,我再次得到了一个视频文件,约27fps。

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.

 
精彩推荐
图片推荐