我现在录了麦克风的音频的Byte,根据网上说的是PCMA格式
然后我想转成AAC格式后RTP到服务器
现在PCMA格式的RTP到服务器,服务器也能接收到音频了
但现在要求是AAC格式,
我网上找的转只有FFMPEG,也是C的,没有学过C正在开始学
然后找了个SharpFFmpeg,不知道这个能不能把我的实时PCMA流,转为AAC流谢谢

解决方案 »

  1.   

    没接触过这个SharpFFmpeg,但是我建议你也参考下这个 音频编解码·实战篇(1)PCM转至AAC(AAC编码)http://blog.csdn.net/poechant/article/details/7435054
      

  2.   

    我搜索SharpFFmpeg里面的
    FFmpeg 类中没有发现有音频编码返回byte[]的方法要怎么实现呢?难道C#就没有办法实现从PCM转到AAC吗?
      

  3.   

    http://www.codeproject.com/Articles/332123/AAC-Encode
    这个是C++的
    但我的是C#的,求解
    谢谢
      

  4.   

    http://www.streamcoders.com/products/msnet.html
    这是一个C#的,但是下载不下来(注册没反应),而且好像是要钱的
      

  5.   

    帮你把上面链接里的c++程序转成了c#,你可以试下: public class AACEncoder : IDisposable
    {
    public const int FF_PROFILE_AAC_MAIN = 0;
    public const int FF_PROFILE_AAC_LOW = 1;
    public const int FF_PROFILE_AAC_SSR = 2;
    public const int FF_PROFILE_AAC_LTP = 3;
    public const int SAMPLE_SIZE = 2; private int _frameBytes;
    private IntPtr _pInputBuffer; private IntPtr _pEncoderOutput;
    private  int _allocOutputSize;

    private IntPtr _pCodecContext; public AACEncoder(int sampleRate, int channels, int audioBitrate)
    {
    FFmpeg.avcodec_register_all(); //Set up audio encoder
    var pCodec = FFmpeg.avcodec_find_encoder(FFmpeg.CodecID.CODEC_ID_AAC);
    if (pCodec == IntPtr.Zero)
    throw new Exception("avcodec_find_encoder: ERROR\n"); _pCodecContext = FFmpeg.avcodec_alloc_context();
    var context = (FFmpeg.AVCodecContext)Marshal.PtrToStructure(_pCodecContext, typeof(FFmpeg.AVCodecContext));
    context.bit_rate = audioBitrate;
    context.sample_fmt = FFmpeg.SampleFormat.SAMPLE_FMT_S16;
    context.sample_rate = sampleRate;
    context.channels = channels;
    context.profile = FF_PROFILE_AAC_MAIN;
    context.codec_type = FFmpeg.CodecType.CODEC_TYPE_AUDIO;
    Marshal.StructureToPtr(context, _pCodecContext, false);

    if (FFmpeg.avcodec_open(_pCodecContext, pCodec) < 0)
    throw new Exception("avcodec_open: ERROR\n"); _allocOutputSize = FFmpeg.FF_MIN_BUFFER_SIZE * 10;
    _pEncoderOutput = Marshal.AllocHGlobal(_allocOutputSize); if (_pEncoderOutput == IntPtr.Zero)
    throw new Exception(string.Format("encoderOutput: malloc Error size({0})", _allocOutputSize)); context = (FFmpeg.AVCodecContext)Marshal.PtrToStructure(_pCodecContext, typeof(FFmpeg.AVCodecContext));
    _frameBytes = context.frame_size * context.channels * SAMPLE_SIZE;
    _pInputBuffer = Marshal.AllocHGlobal(_frameBytes);
    }

    public void Dispose()
    {
    Marshal.FreeHGlobal(_pInputBuffer);
    Marshal.FreeHGlobal(_pEncoderOutput);
    } public byte[] Encode(byte[] rawData, int rawDataSize)
    {
    int p = 0, encoderOutputSize = 0; // Note: revisit the while loop
    // BUG-1 这里有个bug,输入音频的帧长度必须是1024
    while (rawDataSize >= _frameBytes)
    {
    Marshal.Copy(rawData, p, _pInputBuffer, _frameBytes);
    int packetSize = FFmpeg.avcodec_encode_audio(_pCodecContext, _pEncoderOutput, _allocOutputSize,_pInputBuffer);
    encoderOutputSize += packetSize;
    p += _frameBytes;
    rawDataSize -= _frameBytes;
    }
    var result = new byte[encoderOutputSize];
    Marshal.Copy(_pEncoderOutput, result, 0, encoderOutputSize);
    return result;
    }
    }
      

  6.   

    话说回来,如果你做的是webchat程序,没有必要用AAC编/解码。mp3,aac这些都是适合传输音乐的,如果是语音的话用Speex, Truespeech, G.722这些就够了(NAudio的例子中有使用方法)。
    ps. 那个StreamCoder的试用版可以下载,没有问题。
      

  7.   

    你好,因为客户要求最后这些聊天都是生成MP4文件格式的,所以要求H264+AAC
    现在我是一步步来实现
    谢谢