• lame音频编码注意的点


    1.注意每次编码的PCM数据不能太短,如果太短编码函数长期返回-1这样的错误,将导致编码器彻底失效程序奔溃的问题,经测试32000在3200下稳定,大概1/10码率是没有问题的,具体请自行查询或调试

    /*
     * input pcm data, output (maybe) mp3 frames.
     * This routine handles all buffering, resampling and filtering for you.
     *
     * return code     number of bytes output in mp3buf. Can be 0
     *                 -1:  mp3buf was too small
     *                 -2:  malloc() problem
     *                 -3:  lame_init_params() not called
     *                 -4:  psycho acoustic problems
     *
     * The required mp3buf_size can be computed from num_samples,
     * samplerate and encoding rate, but here is a worst case estimate:
     *
     * mp3buf_size in bytes = 1.25*num_samples + 7200
     *
     * I think a tighter bound could be:  (mt, March 2000)
     * MPEG1:
     *    num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512
     * MPEG2:
     *    num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256
     *
     * but test first if you use that!
     *
     * set mp3buf_size = 0 and LAME will not check if mp3buf_size is
     * large enough.
     *
     * NOTE:
     * if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels
     * will be averaged into the L channel before encoding only the L channel
     * This will overwrite the data in buffer_l[] and buffer_r[].
     *
    */

    2.针对PCM数据选择正确的编码方法

    // mp3 encode
        //整形short类型PCM数据
        int recvLen = lame_encode_buffer(_lame, recordingData, recordingData, nsamples, buffer, pcmLen);
       //浮点类型PCM数据
       int recvLen = lame_encode_buffer_interleaved_ieee_float(_lame, recordingData, nsamples, buffer, pcmLen);
        //浮点类型PCM数据
        int recvLen = lame_encode_buffer_ieee_float(_lame, recordingData, recordingData, nsamples, buffer, pcmLen);
  • 相关阅读:
    2块硬盘宝塔只能读取一块?宝塔一键磁盘挂载命令
    Python爬虫入门笔记
    linux搭建web(网站)环境
    织梦dedecms管理模块管理不动卡死解决办法
    php7.1安装swoole扩展
    Linux下centos7、PHP7.1安装Redis扩展教程
    centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)
    Linux各目录及每个目录的详细介绍
    Linux samba的配置和使用
    PHP abstract与interface之间的区别
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/9334593.html
Copyright © 2020-2023  润新知