[FFmpeg-user] decoding and scaling problem using h264

Imran Khan imranhkhan1989 at gmail.com
Fri Feb 1 08:16:06 CET 2013


Hi

I am  encoding frame got from camera using h264. the encoding is working
fine. But when I am trying to decode those frame and print it i am getting
corrupted frames.

this my code.. for decoding the frame and then scaling it into rgb.

 char* VideoDecoder::decode_frame(uint8_t *frame_buffer, size_t
data_length){


len = avcodec_decode_video2(avctx ,frame ,&got_frame ,&avpkt);

if( len < 0){
 return "error while decoding\n";
 }

if( got_frame ){

static struct SwsContext *img_convert_ctx;

     if(img_convert_ctx == NULL) {

      img_convert_ctx = sws_getContext(w, h,
  CTX_PIX_FMT, avctx->width,
  avctx->height, RGB_PIX_FMT,
  SWS_BICUBIC, NULL, NULL, NULL);

       if(img_convert_ctx == NULL) {

    return  "cannot initialize the conversion context!\n";

      }
    }

 sws_scale(img_convert_ctx, frame->data,
 frame->linesize , 0 , h ,
 picture->data, picture->linesize);

rgb_bytes = new uint8_t[size];

memcpy( rgb_bytes , picture->data , size);


please help me to resolve this problem


More information about the ffmpeg-user mailing list