写全各类编码编解码
h264编码
AAC解码 1、声明#define out_sample_fmt AV_SAMPLE_FMT_S16
#define out_channels 2
class AACDecode
{
public:
AACDecode();
~AACDecode();
int DoInit();
void DoUnInit();
bool decodeAACAudio(char *buff, unsigned int buffLen, unsigned int &audioLen);
AVCodecContext* GetContext(){
return _codecCtx;
}
uint8_t *getAudioChunk(){
return dst_data[0];
}
private:
// FFMPEGLibrary _ffmpeg;
int64_t src_ch_layout = AV_CH_LAYOUT_STEREO, dst_ch_layout = AV_CH_LAYOUT_SURROUND;
int src_rate = 44100, dst_rate = 44100;
int src_nb_samples = 1024;
int dst_nb_samples, max_dst_nb_samples;
int dst_nb_channels = 0;
uint8_t **dst_data = NULL;
int dst_linesize;
//uint8_t *_audioChunk = nullptr;
AVCodec *_codec;
AVCodecContext *_codecCtx;
AVFrame* _outputFrame;
SwrContext * _swrCtx = NULL;
int AudioResampling();
};
2、实现
#include "AACDecode.h"
AACDecode::AACDecode()
{
}
AACDecode::~AACDecode()
{
}
int AACDecode::DoInit()
{
FFMPEGLibraryInstance.Load();
if (!FFMPEGLibraryInstance.IsLoaded()){
return -1;
}
if ((_codec = FFMPEGLibraryInstance.AvcodecFindDecoder(AV_CODEC_ID_AAC)) == NULL) {
return false;
}
_codecCtx = FFMPEGLibraryInstance.AvcodecAllocContext(_codec);
if (_codecCtx == NULL) {
return false;
}
if (FFMPEGLibraryInstance.AvcodecOpen(_codecCtx, _codec)
关注
打赏