【问题标题】:How to use different audio encoding bitrate for media recorder android如何为媒体记录器android使用不同的音频编码比特率
【发布时间】:2014-04-24 10:37:57
【问题描述】:

在我的应用程序中,我使用媒体记录器进行音频录制。 我想使用不同的比特率 32,64,128,160 等。

recorder = new MediaRecorder();
    /******Audio Source******/
    try{
        if(audio_source.equals("Camcorder"))
            recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        else if(audio_source.equals("MIC"))
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        else recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    }
    catch(Exception e){
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    }



    /******Audio Channel******/
    try{
        if(audio_channel.equalsIgnoreCase("mono")){
            recorder.setAudioChannels(1);
        }
        else if(audio_channel.equalsIgnoreCase("stereo")){
            recorder.setAudioChannels(2);
        }
    }
    catch(Exception e){
        recorder.setAudioChannels(1);
    }

    System.out.println(" bitrate -- "+bit_rate);

    if (Build.VERSION.SDK_INT >= 10) {
        recorder.setAudioSamplingRate(44100);//44100

    }
    else{
        recorder.setAudioSamplingRate(8000);//44100

    }
    /******AudioEncodingBitRate******/
    try{
        System.out.println(" in try ..."+bit_rate);
        if(bit_rate.equalsIgnoreCase("32")){
            recorder.setAudioEncodingBitRate(32000);
        }
        else if(bit_rate.equalsIgnoreCase("64")){
            recorder.setAudioEncodingBitRate(64000);
        }
        else if(bit_rate.equalsIgnoreCase("96")){
            recorder.setAudioEncodingBitRate(96000);
        }
        else if(bit_rate.equalsIgnoreCase("128")){
            recorder.setAudioEncodingBitRate(128000);
        }
        else if(bit_rate.equalsIgnoreCase("160")){
            recorder.setAudioEncodingBitRate(160000);
        }
    }
    catch(Exception e){
        recorder.setAudioEncodingBitRate(64);
    }
    /******File Format******/
    //recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    if(format.equals(".mp4"))
    {
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    }
    else
    {
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    }

    if (Build.VERSION.SDK_INT >= 10) {
        recorder.setAudioSamplingRate(44100);//44100
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); 
    }
    else{
        recorder.setAudioSamplingRate(8000);//44100
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    }

    recorder.setOutputFile(audiofile.getAbsolutePath()); 
    recorder.prepare();

但是使用上述所有不同的比特率条件,我没有得到任何质量变化。 我该如何使用它?

【问题讨论】:

  • MPEG4 是 容器 格式。您似乎没有指定要使用的 编码器 (setAudioEncoder)。默认编码器是 AMR_NB 的可能性很大,它具有非常低的最大比特率和固定的采样率。
  • 我用过。 AMR_NB.查看更新的代码
  • 在这种情况下,请参阅我之前评论的第二部分。如果您想要更高质量的录音,请指定其他编码器,例如 AAC。
  • 但我想要比特率明智的质量。我提供比特率选项,如 32,64,128 ...
  • AMR_NB 的最大比特率为 12.2 kbit/s,采样率固定(8000 Hz)。再次;如果您期望质量不错的东西,请使用其他编码器。

标签: android mediarecorder bitrate


【解决方案1】:

根据documentation,比特率设置为每秒比特数和

Prepare() 可能会对参数进行额外的检查,以确保指定的比特率是否适用,有时会在内部对传递的比特率进行裁剪,以确保音频录制能够根据平台的能力顺利进行。

我认为,在这种情况下会发生剪辑,因为即使每秒 160 位也低得离谱。

【讨论】:

  • 有什么解决办法吗?因为 32 和 160 比特率文件的大小和声音相同?
  • 使用真实的比特率,例如 32000。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-26
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 2017-04-19
  • 1970-01-01
相关资源
最近更新 更多