[Libav-user] Need a comment

avpicture aykut_avci at hotmail.com
Mon Nov 26 15:52:35 CET 2012


Hello,

I am trying to encode couple of frames in the memory and I have
written/copied code below for this purpose. 
I can reach the memory address of the first picture by bits[0]. Later on I
will add the other frames into the code. This code below is just to see if
everything is running as expected. 

When "ret3=sws_scale..." line is running (performing the conversion from
RGB32 to YUV420), an error appears on the screen saying that "bad dst image
pointers". I have been debugging and checking  outpic parameter, which is
the dst in the parameter list of the scale, but I couldn't find why I am
getting this error. 

Could you please give me a hint for this error?

PS: mfSetContextParameters function is to set all the values for the context
variable. I will copy it at the end of the page.

Thank you very much,

      AVCodec *codec;
      AVCodecContext *c= NULL;
      int  out_size, size, outbuf_size;
      FILE *f;
      AVFrame *picture;
      uint8_t *outbuf, *picture_buf;
      int ret1=0, ret2=0, ret3=0;

      outbuf_size=200000;
      outbuf = (uint8_t *)malloc(outbuf_size);

      picture= avcodec_alloc_frame();

      c=mfSetContextParameters(c, aWidth, aHeight);

      codec = avcodec_find_encoder(CODEC_ID_H264);
      if (!codec) {
          fprintf(stderr, "codec not found\n");
          exit(1);
      }

      /* open it */
      if (avcodec_open(c, codec) < 0) {
          fprintf(stderr, "could not open codec\n");
          exit(1);
      }

      size = c->width * c->height;

      AVFrame* outpic = avcodec_alloc_frame();
      outpic -> pts = 0;
      int nbytes = avpicture_get_size(PIX_FMT_YUV420P, c->width, c->height);

      //create buffer for the output image
      uint8_t* outbuffer = (uint8_t*)av_malloc(nbytes);
      outbuffer=NULL;


      ret1=avpicture_fill((AVPicture*)picture, (uint8_t *) bits[0],
PIX_FMT_RGB32, c->width, c->height);
      ret2=avpicture_fill((AVPicture*)outpic, outbuffer, PIX_FMT_YUV420P,
c->width, c->height);

      struct SwsContext* fooContext = sws_getContext(c->width, c->height,
                                              PIX_FMT_RGB32,
                                              c->width, c->height,
                                              PIX_FMT_YUV420P,
                                              SWS_FAST_BILINEAR, NULL, NULL,
NULL);


      //perform the conversion
      ret3=sws_scale(fooContext, picture->data, picture->linesize, 0,
c->height, outpic->data, outpic->linesize);
      // Here is where I try to convert to YUV

      out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);


-----------------------

    c= avcodec_alloc_context();
    c->bit_rate = 512000;
    c->width = aWidth;
    c->height = aHeight;
    c->time_base.num = 1;
    c->time_base.den = 30;
    c->gop_size = 200;
    c->max_b_frames=0;
    c->bit_rate_tolerance= 40000;
    c->pix_fmt = PIX_FMT_YUV420P;
    c->me_range = 16;
    c->max_qdiff = 1;
    c->qmin = 1;
    c->qmax = 30;
    c->qcompress = 0.6;
    c->me_range = 16;
    c->keyint_min = 120;
    c->refs = 3;
    c->trellis =1;
    c->rtp_payload_size = 500;
    c->level=13; //Level 1.3
    c->me_method=7;
    c->qblur=0.5;
    c->profile=66;//Baseline
    c->thread_count=6;





--
View this message in context: http://libav-users.943685.n4.nabble.com/Need-a-comment-tp4656146.html
Sent from the libav-users mailing list archive at Nabble.com.


More information about the Libav-user mailing list