android - 使用 MediaRecorder 类时如何更改帧率

标签 android video-streaming frame-rate mediarecorder

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

但是我发现我未能降低视频流的帧率。

我使用 H.264 作为我的视频编码器和 AAC 作为我的音频编码器(是的,API LEVEL 10 及更高版本支持它,也就是 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 的视频文件。


那么如何降低视频的帧速率?我正在构建一个实时系统,因此降低比特率对我来说非常重要。 感谢您的宝贵时间!

最佳答案

我也遇到了。来自文档(粗体):

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.

所以看起来你无法真正控制帧速率。您设置的数字用作提示。

关于android - 使用 MediaRecorder 类时如何更改帧率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5407116/

相关文章:

android - 获取 Facebook 专辑封面照片 - Android

java - 在 Android 应用程序中使用 simple_list_item_activated_2

php - 为 HLS 创建主播放列表

amazon-s3 - 是否建议在我的本地服务器上使用 FFMpeg 进行视频转换?

python - 使用 OpenCV cv2.VideoCapture 在 Python 中从 IP 摄像机流式传输视频

xna - 来自少数 Draw() 调用的 Monogame XNA 低帧率

java - LWJGL 和 Slick2D : Crazy Lag! (0.7 FPS)

android - Flutter - 解析 HTML 数据时出错

全屏模式下的 Android 3.1 软键盘

c++ - 外部限制程序帧率