安防视频监控系统视频上云解决方案EasyCVR音频基础知识介绍

时间:2022-07-25
本文章向大家介绍安防视频监控系统视频上云解决方案EasyCVR音频基础知识介绍,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

EasyCVR是TSINGSEE青犀视频研发的视频上云网关,设备端有公网IP,可通过海康SDK、Onvif/RTSP、GB28181、ehome协议接入到EasyCVR中;设备端无公网IP,可通过GB28181、ehome协议接入到EasyCVR中,也可在内网安装EasyNTS设备,与公网建立传输通道,这样即可通过海康SDK、Onvif/RTSP接到EasyCVR中。

本文和大家讲一下EasyCVR中关于音频的一些知识,都是研发在编译当中用到的,大家可以简单了解一下。

1、ffplay 播放pcm,g771

> ffplay -i test.pcm -f s16le -ac 1 -ar 8000 
> ffplay -i test.g711a -f alaw -ac 1 -ar 8000 
> ffplay -i test.g711u -f mulaw -ac 1 -ar 8000 

注意:ac 通道 ar 采样率设置对

-i 指定要播放的文件 -f 编码格式 -ac 通道数 -ar 采样率

2、音频数据大小的计算

采样率16KHZ,位宽16bit,双声道,1分钟采集数据的大小 160002260/1024/1024 采样率16KHZ,位宽32bit,双声道,1分钟采集数据的大小 160004260/1024/1024 采样率16KHZ,位宽16bit,单声道,1分钟采集数据的大小 160002160/1024/1024 采样率16KHZ,位宽8bit,单声道,1分钟采集数据的大小 160001160/1024/1024

3、采样率

例如:16000Hz 表示1s中在连续信号中采集16000次,每一次叫做一个采样点

4、采样深度

例如:16bit 表示每一个采样点采集2个byte的数据,也就是2个字节

5、pcm格式音频存储格式

6、pcm和g711格式互转

#define BIAS        (0x84)      /* Bias for linear code. */  
  
/* 
 * linear2ulaw() - Convert a linear PCM value to u-law 
 * 
 * In order to simplify the encoding process, the original linear magnitude 
 * is biased by adding 33 which shifts the encoding range from (0 - 8158) to 
 * (33 - 8191). The result can be seen in the following encoding table: 
 * 
 *  Biased Linear Input Code    Compressed Code 
 *  ------------------------    --------------- 
 *  00000001wxyza           000wxyz 
 *  0000001wxyzab           001wxyz 
 *  000001wxyzabc           010wxyz 
 *  00001wxyzabcd           011wxyz 
 *  0001wxyzabcde           100wxyz 
 *  001wxyzabcdef           101wxyz 
 *  01wxyzabcdefg           110wxyz 
 *  1wxyzabcdefgh           111wxyz 
 * 
 * Each biased linear code has a leading 1 which identifies the segment 
 * number. The value of the segment number is equal to 7 minus the number 
 * of leading 0's. The quantization interval is directly available as the 
 * four bits wxyz.  * The trailing bits (a - h) are ignored. 
 * 
 * Ordinarily the complement of the resulting code word is used for 
 * transmission, and so the code word is complemented before it is returned. 
 * 
 * For further information see John C. Bellamy's Digital Telephony, 1982, 
 * John Wiley & Sons, pps 98-111 and 472-476. 
 */  
unsigned char  
linear2ulaw(  
    int     pcm_val)    /* 2's complement (16-bit range) */  
{  
    int     mask;  
    int     seg;  
    unsigned char   uval;  
  
    /* Get the sign and the magnitude of the value. */  
    if (pcm_val < 0) {  
        pcm_val = BIAS - pcm_val;  
        mask = 0x7F;  
    } else {  
        pcm_val += BIAS;  
        mask = 0xFF;  
    }  
  
    /* Convert the scaled magnitude to segment number. */  
    seg = search(pcm_val, seg_end, 8);  
  
    /* 
     * Combine the sign, segment, quantization bits; 
     * and complement the code word. 
     */  
    if (seg >= 8)        /* out of range, return maximum value. */  
        return (0x7F ^ mask);  
    else {  
        uval = (seg << 4) | ((pcm_val >> (seg + 3)) & 0xF);  
        return (uval ^ mask);  
    }  
  
}  
  
/* 
 * ulaw2linear() - Convert a u-law value to 16-bit linear PCM 
 * 
 * First, a biased linear code is derived from the code word. An unbiased 
 * output can then be obtained by subtracting 33 from the biased code. 
 * 
 * Note that this function expects to be passed the complement of the 
 * original code word. This is in keeping with ISDN conventions. 
 */  
int  
ulaw2linear(  
    unsigned char   u_val)  
{  
    int     t;  
  
    /* Complement to obtain normal u-law value. */  
    u_val = ~u_val;  
  
    /* 
     * Extract and bias the quantization bits. Then 
     * shift up by the segment number and subtract out the bias. 
     */  
    t = ((u_val & QUANT_MASK) << 3) + BIAS;  
    t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;  
  
    return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));  
}  
  
/* A-law to u-law conversion */  
unsigned char  
alaw2ulaw(  
    unsigned char   aval)  
{  
    aval &= 0xff;  
    return ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :  
        (0x7F ^ _a2u[aval ^ 0x55]));  
}  
  
/* u-law to A-law conversion */  
unsigned char  
ulaw2alaw(  
    unsigned char   uval)  
{  
    uval &= 0xff;  
    return ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :  
        (0x55 ^ (_u2a[0x7F ^ uval] - 1)));  
}  

EasyCVR播放界面