ios使用ffmpeg解码h264数据封装。
#import "FFMpegAVCDecoder.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <libavutil/opt.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#ifdef __cplusplus
};
#endif
@interface FFMpegAVCDecoder(){
AVCodec *_videoCodec;
AVCodecContext *_pCodecCtx;
AVFrame *_pFrame;
char* _yuvBuf;
}
@end
@implementation FFMpegAVCDecoder
-(int)initDecoder{
av_register_all();
/* find the video encoder */
_videoCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
_pCodecCtx = avcodec_alloc_context3(_videoCodec);
if (!_videoCodec)
return -1;
_pCodecCtx->time_base.num = 1;
_pCodecCtx->frame_number = 1; //每包一个视频帧
if(avcodec_open2(_pCodecCtx, _videoCodec,NULL) >= 0)
_pFrame = av_frame_alloc();// Allocate vide