【问题标题】:How to change framerate when using MediaRecorder Class使用 MediaRecorder 类时如何更改帧率
【发布时间】:2011-03-23 14:53:49
【问题描述】:

我尝试使用 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 的视频文件。


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

【问题讨论】:

    标签: android video-streaming frame-rate mediarecorder


    【解决方案1】:

    我也遇到了这个问题。来自文档(我的粗体):

    在某些具有自动帧速率的设备上,这会设置最大帧速率,而不是固定帧速率。 实际帧速率会因光照条件而异

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

    【讨论】:

    • 是的,你是对的。我也得到了那条粗线。实际帧率取决于特定设备(硬件)和操作系统版本。 HTC Desire 的 FPS 似乎比 HTC Desire z 高。而且,Android 2.2.1 的帧率控制方法比 Android 2.3.3 更好。
    【解决方案2】:

    我刚碰到这个。如果你想降低帧率,我们可以使用 recorder.setCaptureRate(double);即 -> recorder.setCapturRate(12.00);recorder.setVideoFrameRate(int) 中更改值时我没有得到任何更改。

    在使用 recorder.setCaptureRate(double) 时,它将以您提到的帧速率录制视频。在 recorder.release() 之后,您的视频将以上述帧速率播放。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-08
      • 2020-05-27
      • 1970-01-01
      • 1970-01-01
      • 2020-02-24
      • 2011-11-26
      • 1970-01-01
      相关资源
      最近更新 更多