2015년 3월 12일 목요일

FFMPEG Video Decode

기본예제 http://ffmpeg.org/doxygen/trunk/decoding_encoding_8c-example.html#a83


  • Decode(H264 Codec)
avcodec_register_all();

AVCodec *pDecodeCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
AVCodecContext *pDecodeCodecCtx = avcodec_alloc_context3(pDecodeCodec);
int nRet = avcodec_open2(pDecodeCodecCtx, pDecodeCodec, NULL);
if(nRet<0)
  fprintf("err\n");

AVPcket avpkt;
av_init_packet(&avpkt);
avpkt.data = (uint8_t*) stream; //영상데이터의 포인터
avpkt.size = sizeOfStream; //영상데이터의 크기
AVFrame *pFrame;
pFrame = avcodec_alloc_frame();
int got_picture = 0;
nRet = avcodec_decode_video2(pDecodeCodecCtx, pFrame, &got_picture, avpkt);

if(nRet < 0)
  fprintf("err\n");
if(got_picture)
  Docode 결과는 pFrame에 저장

이렇게 하면 디코딩이 된돠~
!!!주의 alloc한것들은 모두 free해줄 것.
다음에는 MFC에서 디코드된 결과를 화면에 뿌려주는것 정리해야지

댓글 없음:

댓글 쓰기