1、faac

example

./configure --prefix=$(pwd)/_install

make

make install

/* aac_encode.c */
#include <stdio.h>
#include <faac.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h> int main (int argc, char **argv)
{
unsigned long sampleRate = 8000;
unsigned int numChannels = 1;
unsigned long inputSample = 0;
unsigned long maxOutputBytes = 0;
faacEncHandle encoder;
faacEncConfigurationPtr config;
FILE *rfile = NULL;
FILE *wfile = NULL;
int16_t *pcm_input = NULL;
uint8_t *aac_output = NULL;
int readcount = 0;
int writecount = 0; encoder = faacEncOpen(sampleRate, numChannels, &inputSample, &maxOutputBytes);
config = faacEncGetCurrentConfiguration(encoder);
config->aacObjectType = MAIN;
config->mpegVersion = MPEG4;
config->useLfe = 0;
config->useTns = 1;
config->allowMidside = 1;
/*RAW_STREAM=0, ADTS_STREAM=1*/
config->outputFormat = 1;
config->bitRate = sampleRate;
config->inputFormat = FAAC_INPUT_16BIT;
faacEncSetConfiguration(encoder, config); printf("sampleRate:%ld, numChannels:%d, inputSample:%ld, maxOutputBytes:%ld\n",
sampleRate, numChannels, inputSample, maxOutputBytes); if (argv[1]) {
rfile = fopen(argv[1], "rb");
} else {
printf("try to open input.pcm\n");
rfile = fopen("input.pcm", "rb");
} if (!rfile) {
printf("open error\n");
goto end;
} if (argv[2]) {
wfile = fopen(argv[2], "wb");
} else {
printf("try to open output.aac\n");
wfile = fopen("output.aac", "wb");
} if (!wfile) {
printf("open error\n");
goto end;
} pcm_input = (int16_t *)malloc(inputSample * sizeof(int16_t));
aac_output = (uint8_t *)malloc(maxOutputBytes * sizeof(uint8_t)); /* encode */
while (1) {
int readlen = 0;
int ret = 0; readlen = fread(pcm_input, sizeof(int16_t), inputSample, rfile); ret = faacEncEncode(encoder, (int32_t *)pcm_input, readlen, aac_output, maxOutputBytes); if (ret > 0) {
fwrite(aac_output, sizeof(uint8_t), ret, wfile);
} else if (ret < 0) {
printf("encode error\n");
break;
} readcount += readlen * 2;
writecount += ret; if (!readlen && !ret) {
printf("encode complete, from %d bytes to %d bytes\n", readcount, writecount);
break;
}
} free(pcm_input);
free(aac_output); end:
if (wfile) fclose(wfile);
if (rfile) fclose(rfile);
faacEncClose(encoder);
return 0;
}

Makefile

APP = main

INCLUDE = \
-I ./faac/include

LIB = \
-L ./faac/lib/

SRC  = main.c

CFLAGS =

LDFLAGS = -lfaac

out:
    gcc $(SRC) -o $(APP) $(LIB) $(INCLUDE) $(CFLAGS) $(LDFLAGS)

clean:
    rm -rf *o *.out $(APP)

2、faac/faad <--- > pcm

https://www.audiocoding.com/downloads.html

3、g711 <---> pcm

https://github.com/phoenixZZZ/G711_EncodecAndDecodec

https://github.com/Wenstery/G711AudioStream

https://github.com/escrichov/G711

codec-for-audio-in-G72X-G711-G723-G726-G729

https://github.com/twstx1/codec-for-audio-in-G72X-G711-G723-G726-G729/blob/master/G711_G721_G723/encode.c

非常好的实例,已经用在产品里了,感谢作者!

An ANSI C library for encoding/decoding using the A-law and u-Law.

https://github.com/dystopiancode/pcm-g711

https://blog.csdn.net/szfhy/article/details/52448906

最新文章

  1. input range样式更改,模拟滑块
  2. 经典DOS游戏皇帝攻略(曾经的回忆)
  3. 笔记6:winfrom连接sql server 进行数据交换
  4. JPA学习---第八节:使用JPQL语句进行查询
  5. hadoop2.2编程:mapreduce编程之二次排序
  6. mybatis-generator 代码自动生成工具(maven方式)
  7. 在VS中生成后拷贝文件
  8. 2.如何实现使用VBS脚本程序对直播间自动评论
  9. nicEditors使用方法
  10. .NET之微信消息模板推送
  11. 【Springboot】Springboot整合Thymeleaf模板引擎
  12. nginx日志切割(logrotate或shell脚本)
  13. MySQL-基本命令
  14. i2c初步理解
  15. Mac 下netstat和linux下不一样
  16. 初识Java作业
  17. discuz完善用户资料任务不能完成的解决方法
  18. dongle0
  19. Python类中self的作用
  20. apache服务器设置

热门文章

  1. Memcached 1.4.20 发布,集中式缓存系统
  2. Ajax的两个用法
  3. div允许用户输入
  4. 离线 + 位优化 - SGU 108 Self-numbers 2
  5. JavaScript语言精粹读书笔记- JavaScript对象
  6. 【BZOJ】1030: [JSOI2007]文本生成器(递推+ac自动机)
  7. 【BZOJ】1644: [Usaco2007 Oct]Obstacle Course 障碍训练课(bfs)
  8. linux grub启动密码验证设置
  9. mysql_ado的demo
  10. 还是PHPExcel问题