Hi guy:<div><br></div><div><div>My env is Windows XP and use VC2008 to build my source code.</div><div><br></div><div>The ffmpeg library is to build by Mingw.</div></div><div><br></div><div> I want to conversion yuv420P video stream to mpeg4-es video stream.</div>
<div><span style=""></span><span style=""></span><br></div><div>The program is work but the out file haven't VOL header.</div><div><br></div><div>      </div><div>I use <span class="Apple-style-span" style="background-color: rgb(255, 0, 0);">VC2008 </span>to check my source code. I discover AVCodecContext c->extradata=0x0??</div>
<div><br></div><div>Is the extradata point <span class="Apple-style-span" style="font-family: verdana, MingLiU, PMingLiU; font-size: 15px; line-height: 19px; ">to be equal to zero???</span></div><div><br></div><div><span class="Apple-style-span" style="font-family: verdana, MingLiU, PMingLiU; font-size: 15px; line-height: 19px; "></span>How to do to get vol header?</div>
<div><br></div><div>Please help me, Thank you.</div><div><br></div><div>My source code is below. </div><div><br></div><div><br></div><div><div>void YUV2MP4ES(unsigned char *YUVbuf , unsigned char * MP4buf ,int MP4bufSize)</div>
<div>{</div><div>    AVCodec *codec;</div><div>    AVCodecContext *c= NULL;</div><div>    //uint8_t *extradata;</div><div>    //int extradata_size;</div><div>    int i, out_size, size, x, y, outbuf_size;</div><div>    AVFrame *picture;</div>
<div>    unsigned char *outbuf, *picture_buf;</div><div><br></div><div>   // printf("Video encoding\n");</div><div><br></div><div><br></div><div>    /* find the mpeg4 video encoder */</div><div>    codec = avcodec_find_encoder(CODEC_ID_MPEG4);</div>
<div>    if (!codec) {</div><div>        fprintf(stderr, "codec not found\n");</div><div>        exit(1);</div><div>    }</div><div><br></div><div>    c= avcodec_alloc_context();</div><div>    picture= avcodec_alloc_frame();</div>
<div><br></div><div>    /* put sample parameters */</div><div>    c->bit_rate = 4000000;</div><div>    /* resolution must be a multiple of two */</div><div>    c->width = out_width;</div><div>    c->height = out_height;</div>
<div>    /* frames per second */</div><div>    //c->time_base= (AVRational){1,25};</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>c->time_base.num=1;</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>c->time_base.den=FrameRate;</div>
<div>    c->gop_size = 10; /* emit one intra frame every ten frames */</div><div>    c->max_b_frames=1;</div><div>    c->pix_fmt = PIX_FMT_YUV420P;</div><div>    </div><div><br></div><div>    /* open it */</div><div>
    if (avcodec_open(c, codec) < 0) {</div><div>       // fprintf(stderr, "could not open codec\n");</div><div>        exit(1);</div><div>    }</div><div><br></div><div>    /* alloc image and output buffer */</div>
<div><br></div><div>    size = c->width * c->height;</div><div>    picture_buf = (unsigned char *)malloc ((size * 3) >> 1); /* size for YUV 420 */</div><div><br></div><div>    picture->data[0] = (unsigned char *)YUVbuf;</div>
<div>    picture->data[1] = (unsigned char *)picture->data[0] + size;</div><div>    picture->data[2] = (unsigned char *)picture->data[1] + (size >> 2);</div><div>    picture->data[3] = NULL;</div><div>
    picture->linesize[0] = c->width;</div><div>    picture->linesize[1] = c->width >>1;</div><div>    picture->linesize[2] = c->width >>1;</div><div>    picture->linesize[3] = 0;</div><div>
<br></div><div>    /* encode 1 second of video */</div><div>    </div><div>        /* encode the image */</div><div>        out_size = avcodec_encode_video(c, MP4buf, MP4bufSize, picture);</div><div>        //printf("encoding frame %3d (size=%5d)\n", i, out_size);</div>
<div>        </div><div><br></div><div>    /* add sequence end code to have a real mpeg file */</div><div><br></div><div><br></div><div><br></div><div>    free (picture_buf);</div><div>    avcodec_close(c);</div><div>    av_free(c);</div>
<div>    av_free(picture);</div><div><br></div><div>}</div></div>