// faad2.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include <cassert>
#include <iostream>
#pragma comment(lib, "libfaad2.lib")
#include <stdio.h>
#include <memory.h>
#include <string>
//#ifdef UNICODE
//typedef std::wstring _tstring;
//#else
//typedef std::string _tstring;
//#endif
#include <faad.h>
#include "WavMaker1.h"
const unsigned int g_frmMaxLen = 1024 * 5;
const unsigned int g_BufMaxLen = 1024 * 2048;//1024 * 1024 /**
* fetch one ADTS frame
* buffer 传递的是指针而不是指针的引用真是非常巧妙的一种方式.
*/
int get_one_ADTS_frame(unsigned char* buffer, size_t buf_size, unsigned char* data ,size_t* data_size)
{
size_t size = 0; if(!buffer || !data || !data_size )
{
assert(0);
return -1;
}
while(1)
{
if(buf_size < 7 )
{
assert(0);
return -1;
} if((buffer[0] == 0xff) && ((buffer[1] & 0xf0) == 0xf0) )
{
// profile; 2 uimsbf
// sampling_frequency_index; 4 uimsbf
// private_bit; 1 bslbf
// channel_configuration; 3 uimsbf
// original/copy; 1 bslbf
// home; 1 bslbf
// copyright_identification_bit; 1 bslbf
// copyright_identification_start; 1 bslbf
// frame_length; 13 bslbf
size |= ((buffer[3] & 0x03) <<11); //high 2 bit
size |= buffer[4]<<3; //middle 8 bit
size |= ((buffer[5] & 0xe0)>>5); //low 3bit
break;
}
--buf_size;
++buffer;
} if(buf_size < size)
{
return -1;
} memcpy(data, buffer, size);
*data_size = size; return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
static unsigned char aacFrm[g_frmMaxLen]; //aac 最大帧长
static unsigned char buffer[g_BufMaxLen]; //截取 aac文件的最大长度 string src_file = "mp410.AAC";//输入文件
string dst_file = "mp410.wav";//输出文件
FILE* ifile = NULL; unsigned long samplerate = 0;
unsigned char channels = 0;
NeAACDecHandle decoder = 0;
size_t data_size = 0;
size_t size = 0; NeAACDecFrameInfo frame_info;
memset(&frame_info, 0, sizeof(frame_info));
unsigned char* input_data = buffer;
unsigned char* pcm_data = NULL; ifile = fopen(src_file.c_str(), "rb"); //打开输入文件
const char* p = dst_file.c_str();
WavMaker WavFile(p);
if(!ifile)
{
assert(0);
printf("source or destination file");
return -1;
} //* 读取AAC文件.
data_size = fread(buffer, 1, g_BufMaxLen, ifile); //读取AAC文件长度
//* 打开解码器
decoder = NeAACDecOpen();
//* 初始化解码器
if(get_one_ADTS_frame(buffer, data_size, aacFrm, &size) < 0)
{
assert(0);
return -1;
}
NeAACDecInit(decoder, aacFrm, size, &samplerate, &channels);
printf("samplerate %d, channels %d\n", samplerate, channels);
//* 初始化Wav结构
//WAVEFORMATEX fmt;
//fmt.wFormatTag = WAVE_FORMAT_PCM;
//fmt.nChannels = channels;
//fmt.nSamplesPerSec = samplerate;
//fmt.wBitsPerSample = 16;
//fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample /8;
//fmt.nAvgBytesPerSec = fmt.nBlockAlign * samplerate;
//fmt.cbSize = 0;
//ofile.Init(fmt);
//* 循环解码,写文件 while(get_one_ADTS_frame(input_data, data_size, aacFrm, &size) == 0)
{
pcm_data = (unsigned char*)NeAACDecDecode(decoder, &frame_info, aacFrm, size); //解码信息在frame_info if(frame_info.error > 0)
{
std::cout<<NeAACDecGetErrorMessage(frame_info.error)<<std::endl;
}
else if(pcm_data && frame_info.samples > 0)
{
printf("frame info: bytesconsumed %d, channels %d, header_type %d\
object_type %d, samples %d, samplerate %d\n",
frame_info.bytesconsumed,
frame_info.channels, frame_info.header_type,
frame_info.object_type, frame_info.samples,
frame_info.samplerate);
WavFile.writebody(pcm_data, frame_info.samples * frame_info.channels );//may be 有问题
}
data_size -= size;
input_data += size;
}
NeAACDecClose(decoder);
fclose(ifile);
WavFile.writeheader(frame_info.channels,frame_info.samplerate);
WavFile.closeFile();
return 0;
}

faad解码aac的更多相关文章

  1. H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式(包含AAC部分解析)

    H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +------------ ...

  2. 视音频编解码学习工程:AAC格式分析器

    =====================================================视音频编解码学习工程系列文章列表: 视音频编解码学习工程:H.264分析器 视音频编解码学习工 ...

  3. ffmpeg关于aac解码

    ffmpeg从0.11.3版本开始,默认解码aac为AV_SAMPLE_FMT_FLT (float) 0.11.2以前版本解码aac为AV_SAMPLE_FMT_S16 (16位short型)

  4. (原)从mp4,flv文件中解析出h264和aac,送解码器解码失败

    转载请注明出处:http://www.cnblogs.com/lihaiping/p/5285166.html 今天在做本地文件解码测试,发现从mp4,flv文件中读出来的帧数据,h264和aac帧直 ...

  5. (转) 解密H264、AAC硬件解码的关键扩展数据处理

    出自:http://blog.itpub.net/30168498/viewspace-1576794/       通过上一篇文章,我们用ffmpeg分离出一个多媒体容器中的音视频数据,但是很可能这 ...

  6. AAC 格式分析

    一直在做一个语音项目,到了测试阶段,近来不是很忙,想把之前做的内容整理一下. 关于AAC音频格式基本情况,可参考维基百科http://en.wikipedia.org/wiki/Advanced_Au ...

  7. AAC音频格式详解

    关于AAC音频格式基本情况,可参考维基百科http://en.wikipedia.org/wiki/Advanced_Audio_Coding AAC音频格式分析 AAC音频格式有ADIF和ADTS: ...

  8. C#音视频网络流解码:H264视频和ACC音频

    下面两种方式是直接翻译过来的,还有问题,比如指针的使用和值的传入.考虑C#和C++的差异,还是要抱着怀疑的态度去看待,不一定是对的. H264视频解码网络流: using FFmpeg.AutoGen ...

  9. FLV提取AAC音频单独播放并实现可视化的频谱

    如上图,要实现对FLV直播流中音频的识别,并展示成一个音频相关的动态频谱. 一. 首先了解下什么是声音? 能量波,有频率有振幅,频率高低就是音调,振幅大小就是音量:采样率是对频率采样,采样精度是对幅度 ...

随机推荐

  1. strace命令(收集整理,常看常新)

    starce的用途和参数:http://man.linuxde.net/strace(linux命令大全) strace命令是一个集诊断.调试.统计与一体 的工具,我们可以使用strace对应用的系统 ...

  2. mysql中Can't connect to MySQL server on 'localhost' (10061)

    Can't connect to MySQL server on 'localhost' (10061) 第一问题有两个解决方案: 1)没有启动sql服务,以下是具体步骤: 右键-计算机-管理-服务和 ...

  3. 浅谈T-SQL中的派生表和CTE

    引言 表表达式是一种命名的查询表达式,代表一个有效的关系表.MSSQL支持4种类型的表表达式,它们分别是:派生表.公用表表达式(CTE).视图以及内联表值函数.表表达式并不是物理上真实存在的对象,它们 ...

  4. alter和alert防错?

    在js中这个错误经常容易犯, 那就是 alter 和 alert这两个单词经常写错. 导致js出错, 而不执行! 注意: 在js脚本中, 是 alert 弹出提示框, 而不是 alter ,js中没有 ...

  5. ls按时间排序输出文件列表

    文件转自:http://www.2cto.com/os/201303/197829.html ls按时间排序输出文件列表   首先,ls --help查看ls相关的与时间排序相关的参数:   > ...

  6. oracle 中的dual表简介与用法

    Dual表是每个数据库创建时默认生成的,该表仅有一列一行. 1)分析dual表执行,如下:

  7. [转载]JavaScript内存分析

    https://github.com/CN-Chrome-DevTools/CN-Chrome-DevTools/blob/master/md/Performance-Profiling/javasc ...

  8. 开始使用 Markdown

    (Xee:我最近感觉nyfedit打开有点慢,数据库有点大,试想着用一些其他的方式记录一下学习的过程,才想起了遗忘了很长时间的Markdown,将其分类在HTML下,也是我原本意愿的...) 本文面向 ...

  9. Shader 之 顶点变形

    可以使3D物体通过顶点变形弯曲,常见于跑酷游戏的跑道.可向左.右.上.下弯曲. Shader "Custom/VertexColorCurved" { Properties { / ...

  10. zookeeper集群配置与启动——实战

    1,准备: A:三台linxu服务器: 10.112.29.177 10.112.29.172 10.112.29.174 命令 hostname 得到每台机器的 hostname vm-10-112 ...