[Libav-user] ffmpeg conversion yuv to mpeg4-es , extradata is null !?

Yi Chune Li allen680321 at gmail.com
Wed Apr 27 05:05:20 CEST 2011


Hi guy:

My env is Windows XP and use VC2008 to build my source code.

The ffmpeg library is to build by Mingw.

 I want to conversion yuv420P video stream to mpeg4-es video stream.

The program is work but the out file haven't VOL header.


I use VC2008 to check my source code. I discover AVCodecContext
c->extradata=0x0??

Is the extradata point to be equal to zero???

How to do to get vol header?

Please help me, Thank you.

My source code is below.


void YUV2MP4ES(unsigned char *YUVbuf , unsigned char * MP4buf ,int
MP4bufSize)
{
    AVCodec *codec;
    AVCodecContext *c= NULL;
    //uint8_t *extradata;
    //int extradata_size;
    int i, out_size, size, x, y, outbuf_size;
    AVFrame *picture;
    unsigned char *outbuf, *picture_buf;

   // printf("Video encoding\n");


    /* find the mpeg4 video encoder */
    codec = avcodec_find_encoder(CODEC_ID_MPEG4);
    if (!codec) {
        fprintf(stderr, "codec not found\n");
        exit(1);
    }

    c= avcodec_alloc_context();
    picture= avcodec_alloc_frame();

    /* put sample parameters */
    c->bit_rate = 4000000;
    /* resolution must be a multiple of two */
    c->width = out_width;
    c->height = out_height;
    /* frames per second */
    //c->time_base= (AVRational){1,25};
c->time_base.num=1;
c->time_base.den=FrameRate;
    c->gop_size = 10; /* emit one intra frame every ten frames */
    c->max_b_frames=1;
    c->pix_fmt = PIX_FMT_YUV420P;


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

    /* alloc image and output buffer */

    size = c->width * c->height;
    picture_buf = (unsigned char *)malloc ((size * 3) >> 1); /* size for YUV
420 */

    picture->data[0] = (unsigned char *)YUVbuf;
    picture->data[1] = (unsigned char *)picture->data[0] + size;
    picture->data[2] = (unsigned char *)picture->data[1] + (size >> 2);
    picture->data[3] = NULL;
    picture->linesize[0] = c->width;
    picture->linesize[1] = c->width >>1;
    picture->linesize[2] = c->width >>1;
    picture->linesize[3] = 0;

    /* encode 1 second of video */

        /* encode the image */
        out_size = avcodec_encode_video(c, MP4buf, MP4bufSize, picture);
        //printf("encoding frame %3d (size=%5d)\n", i, out_size);


    /* add sequence end code to have a real mpeg file */



    free (picture_buf);
    avcodec_close(c);
    av_free(c);
    av_free(picture);

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20110427/8a01edda/attachment.html>


More information about the Libav-user mailing list