• faac编码aac


    // faacode.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <faac.h>
    #include <stdio.h>
    
    typedef unsigned long   ULONG;
    typedef unsigned int    UINT;
    typedef unsigned char   BYTE;
    //typedef char            _TCHAR;
    
    #pragma comment(lib,"libfaac.lib")
    
    int main(int argc, _TCHAR* argv[])
    {
    	ULONG nSampleRate = 44100;  // 采样率
    	UINT nChannels = 2;         // 声道数
    	UINT nPCMBitSize = 16;      // 单样本位数
    	ULONG nInputSamples = 0;
    	ULONG nMaxOutputBytes = 0;
    
    	int nRet;
    	faacEncHandle hEncoder;
    	faacEncConfigurationPtr pConfiguration; 
    
    	int nBytesRead;
    	int nPCMBufferSize;
    	BYTE* pbPCMBuffer;
    	BYTE* pbAACBuffer;
    
    	FILE* fpIn; // WAV file for input
    	FILE* fpOut; // AAC file for output
    
    	fpIn = fopen("test.wav", "rb");//  resample.pcm
    	fpOut = fopen("test.aac", "wb");//  resample.aac
    
    	// (1) Open FAAC engine
    	hEncoder = faacEncOpen(nSampleRate, nChannels, &nInputSamples, &nMaxOutputBytes);
    	if(hEncoder == NULL)
    	{
    		printf("[ERROR] Failed to call faacEncOpen()
    ");
    		return -1;
    	}
    
    	nPCMBufferSize = nInputSamples * nPCMBitSize / 8;
    	pbPCMBuffer = new BYTE [nPCMBufferSize];
    	pbAACBuffer = new BYTE [nMaxOutputBytes];
    
    	// (2.1) Get current encoding configuration
    	pConfiguration = faacEncGetCurrentConfiguration(hEncoder);
    	
    	pConfiguration->inputFormat = FAAC_INPUT_16BIT;
    
    	// (2.2) Set encoding configuration
    	nRet = faacEncSetConfiguration(hEncoder, pConfiguration);
    
    	//如果是wav格式,先读取前面的
    	fseek(fpIn,58,SEEK_SET);
    	for(int i = 0; 1; i++)
    	{
    		// 读入的实际字节数,最大不会超过nPCMBufferSize,
    nBytesRead = fread(pbPCMBuffer, 1, nPCMBufferSize, fpIn); // 输入样本数,用实际读入字节数计算,一般只有读到文件尾时才不是nPCMBufferSize/(nPCMBitSize/8); nInputSamples = nBytesRead / (nPCMBitSize / 8); // (3) Encode nRet = faacEncEncode( hEncoder, (int*) pbPCMBuffer, nInputSamples, pbAACBuffer, nMaxOutputBytes); fwrite(pbAACBuffer, 1, nRet, fpOut); printf("%d: faacEncEncode returns %d ", i, nRet); if(nBytesRead <= 0) { break; } } // (4) Close FAAC engine nRet = faacEncClose(hEncoder); delete[] pbPCMBuffer; delete[] pbAACBuffer; fclose(fpIn); fclose(fpOut); //getchar(); return 0; }
  • 相关阅读:
    ELF静态链接
    linux
    百度图表插件
    秀米(图文编辑)
    Html 助手
    在型原型工具
    AnalyticDB
    H5 (webApi) 接口帮助文档
    H5 拖拽读取文件和文件夹
    mongodb int字段的一个小坑
  • 原文地址:https://www.cnblogs.com/welen/p/3666284.html
Copyright © 2020-2023  润新知