[Libav-user] Decoding Problem (got_picture always return 0)

Việt Hùng Nguyễn hungtrodt5 at gmail.com
Sat Mar 24 02:05:01 CET 2012


Hi,

It seems you got some mistakes in your code.
1- In your conversion colour space code, not all stride is frameWidth. For
YUV420p, stride for Cr, Cb is frameWidth/2
2- After you call x264_encoder_encode, you should call x264_nal_encode
3- When send data to ffmpeg h264 decoder, remember that is annex-B data
stream

Hung, Nguyen Viet

On Fri, Mar 23, 2012 at 11:37 PM, ZHAO Yinxia <hydezhao at gmail.com> wrote:

> Thank you  Hung, Nguyen Viet ,
>
> I've added these 32 bits headers, but it does not work. my program at
> server end is something like this:
>
> int saveFrame(void *ctx, unsigned char *pixels, int frameWidth, int
> frameHeight, unsigned char **out, int *len)
> {
> Ctx *c = (Ctx*)ctx;
> // convert RGB colorspace image buffer to YCrCb format
>  RGB2YUV(frameWidth, frameHeight, pixels, pic_in.img.plane[0],
> pic_in.img.plane[1], pic_in.img.plane[2], false);
>
> for (int i =0; i<4; i++)
>  {
>         c->picture.img.plane[i] = pic_in.img.plane[i];
>  c->picture.img.i_stride[i] = frameWidth;
> }
>
> // c->picture.i_pts=c->get_pts(c);
>
> x264_picture_t pic_out;
>         x264_nal_t* nals;
> x264_picture_t *pic = &c->picture;
>         int i_nals;
>         int frame_size = x264_encoder_encode(c->x264, &nals, &i_nals, pic,
> &pic_out);
>
>         if( frame_size )
> encode_nals(c, nals, i_nals);
>  *out = (unsigned char *)c->output;
> *len = c->output_datasize;
>  if (i_nals > 0) {
> c->info_valid = 1;
>  c->info_key_frame = pic_out.b_keyframe;
> c->info_pts = pic_out.i_pts;
>  c->info_dts = pic_out.i_dts;
> }
>  else return 0;
>
>     return 1;
> }
>
> static int encode_nals (Ctx *c, x264_nal_t *nals, int nal_cnt)
> {
> char *pout = (char*)c->output;
> c->output_datasize = 0;
>  for (int i = 0; i < nal_cnt; i++) {
>  if (c->output_datasize + nals[i].i_payload > c->output_bufsize) {
> c->output_bufsize =
> (c->output_datasize+nals[i].i_payload+frameWidth)/frameWidth * frameHeight;
>  c->output = realloc(c->output, c->output_bufsize);
> }
> memcpy(pout+c->output_datasize, nals[i].p_payload, nals[i].i_payload);
>  c->output_datasize += nals[i].i_payload;
> }
> return c->output_datasize;
> }
>
> Sincerely,
> Yinxia
>
>
> 2012/3/23 Việt Hùng Nguyễn <hungtrodt5 at gmail.com>
>
>> And before you send data to decoder, remember put 4 bytes header 0x00
>> 0x00 0x00 0x01.
>>
>> Hung, Nguyen Viet
>>
>>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120324/95ea18df/attachment.html>


More information about the Libav-user mailing list