大家好,我使用MediaRecorder Class录视频,却发现无法修改帧率视频我用的AVC编码,音频我用的AAC编码(这个是API LEVEL 10以后支持的)我的主体源码如下:
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();但是debug说
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了大家帮忙看看为什么呢?

解决方案 »

  1.   

    我还尝试过使用CamcorderProfile来避免对recorder的复杂配置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书上说的QUALITY_LOW Profile配置是12fps,但是我录出来的视频还是27fps,这是为什么呢?
      

  2.   

    /**
    * Uses the settings from a CamcorderProfile object for recording. This method should
    * be called after the video AND audio sources are set, and before setOutputFile().
    * 使用来自记录CamcorderProfile对象的设置。这种方法应该调用在
    * 被命名后的视频和音频源设置和setOutputFile()之前。
    * @param profile the CamcorderProfile to use
    * @see android.media.CamcorderProfile
    */
    public void setProfile(CamcorderProfile profile) {
    setOutputFormat(profile.fileFormat); //设置在录制过程中产生的输出文件格式
    setVideoFrameRate(profile.videoFrameRate); //设置视频的帧速率,以被捕获setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); //设置宽度和高度的视频捕获
    setVideoEncodingBitRate(profile.videoBitRate); //设置视频编码录音比特率
    setAudioEncodingBitRate(profile.audioBitRate);//设置音频编码录音比特率
    setAudioChannels(profile.audioChannels);//设置录制的音频通道数
    setAudioSamplingRate(profile.audioSampleRate); //设置音频采样率记录
    setVideoEncoder(profile.videoCodec); //设置视频编码器可用于录制。如果这个方法不叫,输出文件将不包含视频
    setAudioEncoder(profile.audioCodec); //设置音频编码器可用于录制 如果是录音一定要设置哦不然没有音频哦
    }
    http://hi.baidu.com/adnroidorg/blog/item/1859def9590b839959ee909a.htmlhttp://stackoverflow.com/questions/5407116/how-to-change-framerate-when-using-mediarecorder-class
    和楼主同样的问题,不会是楼主问的吧?
      

  3.   

    setVideoFrameRate
    public void setVideoFrameRate(int rate)
                           throws IllegalStateException
    Sets the frame rate of the video to be captured. Must be called after setVideoSource(). Call this after setOutFormat() but before prepare(). 
    设置frame率,必须在setVideoSource,setOutFormat之后,prepare()之前调用。Parameters:
    rate - the number of frames per second of video to capture 
    Throws: 
    IllegalStateException - if it is called after prepare() or before setOutputFormat().http://www.androidjavadoc.com/1.0_r1_src/android/media/MediaRecorder.html#setVideoFrameRate(int)
      

  4.   


    没错,确实都是我问的,昨晚问的Stack Overflow,放了一晚上(应该是米国的一个白天)都没人理我...
      

  5.   

    我确实是按这个顺序调用的,不按这个顺序调用程序会down掉,什么都不会录出来,我的确是录出文件了。老大你这翻译都翻错了* 使用来自记录CamcorderProfile对象的设置。这种方法应该调用在
    * 视频和音频源设置[color=#FF0000]之后
    和setOutputFile()之前。[/color]看我一楼,我也是这么设置的。
    不这么设置什么都录不出来的,我只是想录一个不是27fps的。
      

  6.   

    是不是摄像头硬件不支持修改zhen数?
      

  7.   

    不知道,我用的Desire,我来试试Desire z~
      

  8.   

    public void setVideoFrameRate (int rate) 
    Since: API Level 3 Sets the frame rate of the video to be captured. Must be called after setVideoSource(). Call this after setOutFormat() but before prepare().Parameters
    rate  the number of frames per second of video to capture Throws
    IllegalStateException  if it is called after prepare() or before setOutputFormat(). NOTE: 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.  
    在有些自动帧率的设备上,这个只是设置最大帧率。
      

  9.   

    好像是有关
    我用desire z(ROM:CM 6.1.1 ANDROID 2.2.1)音频用的AMR_NB编码(2.2的android不支持AAC),设定15fps,输出22fps
    我用desire (ROM:OXYGEN ANDROID 2.3.2)音频用AMR_NB编码设定15fps,输出29fps
      

  10.   


    帧率一般都不是固定的,在一个值附近浮动,你随意打开一个电影,用potplayer之类的播放器看看文件属性中的fps,一直都是变化的。
      

  11.   


    应该是和系统有关,第三台手机: Desire (ROM: Stock Sense UI Android 2.2),音频用AMR_NB编码设定15fps,输出18fps
      

  12.   


    不知道,那得看Android中的源码了估计,接口都是一样的,2.2的帧率就是比2.3.3更接近,当然也有可能是Oxygen这个非主流ROM改了什么。不过Oxygen ROM说自己尽量做到和官方系统最小的改动,比CM小。
      

  13.   

    Androd上,实际上测出来的效果:H264编码的时候,采用的就是可变帧率,设置帧率没用。