picture_ptr = picture;
void write_video_frame(AVFormatContext *oc, AVStream *st){    int out_size, ret;    AVCodecContext *c;    AVFrame *picture_ptr;        c = &st->codec;        if (frame_count >= STREAM_NB_FRAMES) {        /* no more frame to compress. The codec has a latency of a few           frames if using B frames, so we get the last frames by           passing a NULL picture */        picture_ptr = NULL;    } else {        if (c->pix_fmt != PIX_FMT_YUV420P) {            /* as we only generate a YUV420P picture, we must convert it               to the codec pixel format if needed */            fill_yuv_image(tmp_picture, frame_count, c->width, c->height);            img_convert((AVPicture *)picture, c->pix_fmt,                         (AVPicture *)tmp_picture, PIX_FMT_YUV420P,                        c->width, c->height);        } else {            fill_yuv_image(picture, frame_count, c->width, c->height);        }        picture_ptr = picture;    }        if (oc->oformat->flags & AVFMT_RAWPICTURE) {        /* raw video case. The API will change slightly in the near           futur for that */        AVPacket pkt;        av_init_packet(&pkt);                pkt.flags |= PKT_FLAG_KEY;        pkt.stream_index= st->index;        pkt.data= (uint8_t *)picture_ptr;        pkt.size= sizeof(AVPicture);                ret = av_write_frame(oc, &pkt);    } else {        /* encode the image */        out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, picture_ptr);        /* if zero size, it means the image was buffered */        if (out_size != 0) {            AVPacket pkt;            av_init_packet(&pkt);                        pkt.pts= c->coded_frame->pts;            if(c->coded_frame->key_frame)                pkt.flags |= PKT_FLAG_KEY;            pkt.stream_index= st->index;            pkt.data= video_outbuf;            pkt.size= out_size;                        /* write the compressed frame in the media file */            ret = av_write_frame(oc, &pkt);        } else {            ret = 0;        }    }    if (ret != 0) {        fprintf(stderr, "Error while writing video frame\n");        exit(1);    }    frame_count++;}