使用 MediaRecorder 类时如何更改帧速率
我尝试使用 MediaRecorder 类录制视频。
但是我发现我未能降低视频流的帧速率。
我使用 H.264 作为我的视频编码器,使用 AAC 作为我的音频编码器(是的,API LEVEL 10 及更高版本支持它,AKA Android 2.3.3+) 主要来源如下。
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();
然而我得到的调试信息是:
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)
很奇怪,我还收到一条错误消息:
03-22 22:39:41.380: ERROR/VENC_ENC(662): Bitrate 192000
最后,我得到了一个帧速率接近 28fps 的 mp4 文件。
我还尝试使用最低的 CamcorderProfile
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();
并注释记录器的详细配置。
正如Pro Android Media这本书的第242页所说,我会得到15fps的视频文件。然而,我再次得到了大约27fps的视频文件。
那么如何降低视频的帧速率?我正在构建一个实时系统,因此降低比特率对我来说非常重要。 谢谢您的宝贵时间!
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也刚刚遇到过这个。来自文档(粗体我的):
所以看起来你无法真正控制帧速率。您设置的数字将用作提示。
I have just ran into this too. From the docs (bold mine):
So it looks like you can't really control the frame rate. The number you set is used like a hint.
我刚刚遇到了这个。如果你想降低帧率,我们可以使用recorder.setCaptureRate(double);即-> recorder.setCapturRate(12.00);
在更改 recorder.setVideoFrameRate(int) 中的值时,我没有得到任何更改。
使用 recorder.setCaptureRate(double) 时,它将以您提到的帧速率录制视频。在 recorder.release() 之后,您的视频将以提到的帧速率播放。
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.