oc = av_mallocz(sizeof(AVFormatContext));
oc = av_alloc_format_context();
int main(int argc, char **argv){    const char *filename;    AVOutputFormat *fmt;    AVFormatContext *oc;    AVStream *audio_st, *video_st;    double audio_pts, video_pts;    int i;    /* initialize libavcodec, and register all codecs and formats */    av_register_all();        if (argc != 2) {        printf("usage: %s output_file\n"               "API example program to output a media file with libavformat.\n"               "The output format is automatically guessed according to the file extension.\n"               "Raw images can also be output by using '%%d' in the filename\n"               "\n", argv[0]);        exit(1);    }        filename = argv[1];    /* auto detect the output format from the name. default is       mpeg. */    fmt = guess_format(NULL, filename, NULL);    if (!fmt) {        printf("Could not deduce output format from file extension: using MPEG.\n");        fmt = guess_format("mpeg", NULL, NULL);    }    if (!fmt) {        fprintf(stderr, "Could not find suitable output format\n");        exit(1);    }        /* allocate the output media context */    oc = av_mallocz(sizeof(AVFormatContext));    if (!oc) {        fprintf(stderr, "Memory error\n");        exit(1);    }    oc->oformat = fmt;    snprintf(oc->filename, sizeof(oc->filename), "%s", filename);    /* add the audio and video streams using the default format codecs       and initialize the codecs */    video_st = NULL;    audio_st = NULL;    if (fmt->video_codec != CODEC_ID_NONE) {        video_st = add_video_stream(oc, fmt->video_codec);    }    if (fmt->audio_codec != CODEC_ID_NONE) {        audio_st = add_audio_stream(oc, fmt->audio_codec);    }    /* set the output parameters (must be done even if no       parameters). */    if (av_set_parameters(oc, NULL) < 0) {        fprintf(stderr, "Invalid output format parameters\n");        exit(1);    }    dump_format(oc, 0, filename, 1);    /* now that all the parameters are set, we can open the audio and       video codecs and allocate the necessary encode buffers */    if (video_st)        open_video(oc, video_st);    if (audio_st)        open_audio(oc, audio_st);    /* open the output file, if needed */    if (!(fmt->flags & AVFMT_NOFILE)) {        if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {            fprintf(stderr, "Could not open '%s'\n", filename);            exit(1);        }    }        /* write the stream header, if any */    av_write_header(oc);        for(;;) {        /* compute current audio and video time */        if (audio_st)            audio_pts = (double)audio_st->pts.val * oc->pts_num / oc->pts_den;        else            audio_pts = 0.0;                if (video_st)            video_pts = (double)video_st->pts.val * oc->pts_num / oc->pts_den;        else            video_pts = 0.0;        if ((!audio_st || audio_pts >= STREAM_DURATION) &&             (!video_st || video_pts >= STREAM_DURATION))            break;                /* write interleaved audio and video frames */        if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {            write_audio_frame(oc, audio_st);        } else {            write_video_frame(oc, video_st);        }    }    /* close each codec */    if (video_st)        close_video(oc, video_st);    if (audio_st)        close_audio(oc, audio_st);    /* write the trailer, if any */    av_write_trailer(oc);        /* free the streams */    for(i = 0; i < oc->nb_streams; i++) {        av_freep(&oc->streams[i]);    }    if (!(fmt->flags & AVFMT_NOFILE)) {        /* close the output file */        url_fclose(&oc->pb);    }    /* free the stream */    av_free(oc);    return 0;}