zoukankan      html  css  js  c++  java
  • 生成aac sdp文件

    编码

    void aac_rtp_create_sdp(uint8_t *file, uint8_t *ip, uint16_t port,
                            uint16_t profile,
                            uint16_t chn,
                            uint16_t freq, uint16_t type)
    {
        char buff[1024] = {0};
        char typeName[64] = {0};
        // char demo[] =
        //     "m=audio 9832 RTP/AVP 97
    "
        //     "a=rtpmap:97 mpeg4-generic/44100/2
    "
        //     "a=fmtp:97 sizeLength=13;mode=AAC-hbr;config=1210;
    "
        //     "c=IN IP4 127.0.0.1";
        char demo[] =
            "m=audio %d RTP/AVP %d
    "
            "a=rtpmap:%d %s/%d/%d
    "
            "a=fmtp:%d streamtype=5;profile-level-id=1;sizeLength=13;IndexLength=3;indexDeltaLength=3;mode=AAC-hbr;config=%d;
    "
            "c=IN IP4 %s";
        uint16_t config = 1410, _freq = 8;
        int fd;
    
        strcpy(typeName, "mpeg4-generic");      // 这里先支持AAC该类型的
    
        if(freq == 96000) _freq = 0;
        else if(freq == 88200) _freq = 1;
        else if(freq == 64000) _freq = 2;
        else if(freq == 48000) _freq = 3;
        else if(freq == 44100) _freq = 4;
        else if(freq == 32000) _freq = 5;
        else if(freq == 24000) _freq = 6;
        else if(freq == 22050) _freq = 7;
        else if(freq == 16000) _freq = 8;
        else if(freq == 12000) _freq = 9;
        else if(freq == 11025) _freq = 10;
        else if(freq == 8000) _freq = 11;
        else if(freq == 7350) _freq = 12;
        // 从aac adts header读取出来的profile是被减1的
        config = profile + 1;     config <<= 5; // 5    aac的profile, 通常情况是1, 或者2
        config |= _freq; config <<= 4;  //aac的采样频率的索引
        config |= chn; config <<= 3;    //
        //转成16进制
        config = ((config>>12)&0xF)*1000 + ((config>>8)&0xF)*100 + ((config>>4)&0xF)*10 + ((config>>0)&0xF);
        snprintf(buff, sizeof(buff), demo, port, type, type, typeName, freq, chn, type, config, ip);
        remove(file);
        if((fd = fopen(file, "wt")) > 0)
        {
            fwrite(buff, strlen(buff), 1, fd);
            fclose(fd);
        }
    }

    sdp文件

    m=audio 9832 RTP/AVP 97
    a=rtpmap:97 mpeg4-generic/48000/2
    a=fmtp:97 streamtype=5;profile-level-id=1;sizeLength=13;IndexLength=3;indexDeltaLength=3;mode=AAC-hbr;config=2190;
    c=IN IP4 10.143.44.169

    "m=" video:媒体名称  9832:端口  RTP/AVP:传输协议  97:RTP协议中的pt值

    "a=rtpmap"97:RTP协议中的pt值  mpeg4-generic:音频编码  48000:音频采样率  2:通道数

    "a=fmtp"streamtype:aac为5  profile-level-id: 1表示低复杂度类型   sizeLength:表示AU-size占用位数  

      IndexLength:表示AU-Index占用位数  indexDeltaLength:表示AU-Index-delta占用位数  mode:表示编码模式

      config:16进制2190 转化为二进制:00100 0011 0010 000

        00100:aac的profile,这里为5

        0011:3,表示采样率为48000

        0010: 2,表示通道数

    采样率表格

    表示的采样频率
    0 96000,
    1 88200,
    2 64000,
    3 48000,
    4 44100,
    5 32000,
    6 24000,
    7 22050,
    8 16000,
    9 12000,
    10 11025,
    11 8000,
    12 7350
    15 表示自定义的采样频率, 一般不会出现
  • 相关阅读:
    通过电脑chrome调试手机真机打开的微信H5页面,调试电脑微信H5页面
    关于神策埋点数据采集
    jmeter控制仅一次登录的三种方案
    win10下mysql8.0.19解压版的安装教程
    mysql中的case when then 的用法
    python+openpyxl的excel的相关读写
    使用Gitlab-CI 实现NetCore项目Docker化并部署到阿里云K8S
    NetCore 中间件获取请求报文和返回报文
    WebApi 通过拦截器设置特定的返回格式
    NetCore AutoMapper的封装
  • 原文地址:https://www.cnblogs.com/vczf/p/13941581.html
Copyright © 2011-2022 走看看