Thank you
Hung, Nguyen Viet ,<div><br></div><div>I've added these 32 bits headers, but it does not work. my program at server end is something like this:</div><div><br></div><div><div><font face="'courier new', monospace">int saveFrame(void *ctx, unsigned char *pixels, int frameWidth, int frameHeight, unsigned char **out, int *len)</font></div>
<div><font face="'courier new', monospace">{</font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>Ctx *c = (Ctx*)ctx;</font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>// convert RGB colorspace image buffer to YCrCb format</font></div>
<div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>RGB2YUV(frameWidth, frameHeight, pixels, pic_in.img.plane[0], pic_in.img.plane[1], pic_in.img.plane[2], false);</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>for (int i =0; i<4; i++)</font></div>
<div>
<font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>{</font></div><div><font face="'courier new', monospace"> c->picture.img.plane[i] = pic_in.img.plane[i]; </font></div>
<div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>c->picture.img.i_stride[i] = frameWidth;</font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace">//<span class="Apple-tab-span" style="white-space:pre"> </span>c->picture.i_pts=c->get_pts(c);</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>x264_picture_t pic_out;</font></div><div>
<font face="'courier new', monospace"> x264_nal_t* nals;</font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>x264_picture_t *pic = &c->picture;</font></div>
<div><font face="'courier new', monospace"> int i_nals;</font></div><div><font face="'courier new', monospace"> int frame_size = x264_encoder_encode(c->x264, &nals, &i_nals, pic, &pic_out);</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> if( frame_size )</font></div><div><span class="Apple-tab-span" style="font-family:'courier new',monospace;white-space:pre"> </span><span style="font-family:'courier new',monospace">encode_nals(c, nals, i_nals);</span></div>
<div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>*out = (unsigned char *)c->output;</font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>*len = c->output_datasize;</font></div>
<div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>if (i_nals > 0) {</font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>c->info_valid = 1;</font></div>
<div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>c->info_key_frame = pic_out.b_keyframe;</font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>c->info_pts = pic_out.i_pts;</font></div>
<div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>c->info_dts = pic_out.i_dts;</font></div><div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div>
<div><font face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>else return 0;</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> return 1;</font></div>
<div><font face="'courier new', monospace">}</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><div>static int encode_nals (Ctx *c, x264_nal_t *nals, int nal_cnt)</div>
<div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>char *pout = (char*)c->output;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>c->output_datasize = 0;</div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span>for (int i = 0; i < nal_cnt; i++) {</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>if (c->output_datasize + nals[i].i_payload > c->output_bufsize) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>c->output_bufsize = (c->output_datasize+nals[i].i_payload+frameWidth)/frameWidth * frameHeight;</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>c->output = realloc(c->output, c->output_bufsize);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>memcpy(pout+c->output_datasize, nals[i].p_payload, nals[i].i_payload);</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>c->output_datasize += nals[i].i_payload;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return c->output_datasize;</div>
<div>}</div><div><br></div><div>Sincerely,</div><div>Yinxia</div><div><br></div></font></div><br><div class="gmail_quote">2012/3/23 Việt Hùng Nguyễn <span dir="ltr"><<a href="mailto:hungtrodt5@gmail.com">hungtrodt5@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>And before you send data to decoder, remember put 4 bytes header 0x00 0x00 0x00 0x01.</p>
<p>Hung, Nguyen Viet</p><div class="HOEnZb"><div class="h5">
<div class="gmail_quote"><br></div></div></div></blockquote></div></div>