AAC--ffmpeg解码

新版ffmpeg 解码aac 默认output 为 AV_SAMPLE_FMT_FLTP//无法播放,要转格式才能播放----即重采样swr转换格式

通过ffmpeg对acc音频解码后,音频的存储格式为AV_SAMPLE_FMT_FLTP,需要将其转换为AV_SAMPLE_FMT_S16P后,用dsound进行播放。

AV_SAMPLE_FMT_FLTP转AV_SAMPLE_FMT_S16P,参考官网:
http://ffmpeg.org/doxygen/trunk/transcode_aac_8c-example.html

写wav文件头//后续只要嫁给你ffmpeg得到的pkt.data写进去就行了

static int write_wav_header(int iBitPerSample,int iChans,   unsigned char ucFormat         ,int iSampleRate,int iTotalSamples,FILE*pFile)
{
     
	unsigned char header[44];
	unsigned char* p = header;
	unsigned int bytes = (iBitPerSample + 7) / 8;
	float data_size = (float)bytes * iTotalSamples;
	unsigned long word32;
 
	*p++ = 'R'; *p++ = 'I'; *p++ = 'F'; *p++ = 'F';
 
	word32 = (data_size + (44 - 8) < (float)MAXWAVESIZE) ?
		(unsigned long)data_size + (44 - 8)  :  (unsigned long)MAXWAVESIZE;
	*p++ = (unsigned char)(word32 >>  0);
	*p++ = (unsigned char)(word32 >>  8);
	*p++ = (unsigned char)(word32 >> 16);
	*p++ = (unsigned char)(word32 >> 24);
 
	*p++ = 'W'; *p++ = 'A'; *p++ = 'V'; *p++ = 'E';
 
	*p++ = 'f'; *p++ = 'm'; *p++ = 't'; *p++ = ' ';
 
	*p++ = 0x10; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00;
 
	if (ucFormat == AV_SAMPLE_FMT_FLT)
	{
     
		*p++ = 0x03; *p++ = 0x00;
	} else {
     
		*p++ = 0x01; *p++ = 0x00;
	}
 
	*p++ = (unsigned char)(iChans >> 0);
	*p++ = (unsigned char)(iChans >> 8);
 
	word32 = (unsigned long)(iSampleRate + 0.5);
	*p++ = (unsigned char)(word32 >>  0);
	*p++ = (unsigned char)(word32 >>  8);
	*p++ = (unsigned char)(word32 >> 16);
	*p++ = (unsigned char)(word32 >> 24);
 
	word32 = iSampleRate * bytes * iChans;
	*p++ = (unsigned char)(word32 >>  0);
	*p++ = (unsigned char)(word32 >>  8);
	*p++ = (unsigned char)(word32 >> 16);
	*p++ = (unsigned char)(word32 >> 24);
 
	word32 = bytes * iChans;
	*p++ = (unsigned char)(word32 >>  0);
	*p++ = (unsigned char)(word32 >>  8);
 
	*p++ = (unsigned char)(iBitPerSample >> 0);
	*p++ = (unsigned char)(iBitPerSample >> 8);
 
	*p++ = 'd'; *p++ = 'a'; *p++ = 't'; *p++ = 'a';
 
	word32 = data_size < MAXWAVESIZE ?
		(unsigned long)data_size : (unsigned long)MAXWAVESIZE;
	*p++ = (unsigned char)(word32 >>  0);
	*p++ = (unsigned char)(word32 >>  8);
	*p++ = (unsigned char)(word32 >> 16);
	*p++ = (unsigned char)(word32 >> 24);
 
	return fwrite(header, sizeof(header), 1, pFile);
}

你可能感兴趣的:(AAC)