void avformat_free_context(AVFormatContext *s)
{
    int i;
    AVStream *st;
    av_opt_free(s);
    if (s->iformat && s->iformat->priv_class && s->priv_data)
        av_opt_free(s->priv_data);
    for(i=0;i<s->nb_streams;i++) {
        st = s->streams[i];
        if (st->parser) {
            av_parser_close(st->parser);
            av_free_packet(&st->cur_pkt);
        }
        av_dict_free(&st->metadata);
        av_free(st->index_entries);
        av_free(st->codec->extradata);
        av_free(st->codec->subtitle_header);
        av_free(st->codec);
        av_free(st->priv_data);
        av_free(st->info);
        av_free(st);
    }
    for(i=s->nb_programs-1; i>=0; i--) {
        av_dict_free(&s->programs[i]->metadata);
        av_freep(&s->programs[i]->stream_index);
        av_freep(&s->programs[i]);
    }
    av_freep(&s->programs);
    av_freep(&s->priv_data);
    while(s->nb_chapters--) {
        av_dict_free(&s->chapters[s->nb_chapters]->metadata);
        av_free(s->chapters[s->nb_chapters]);
    }
    av_freep(&s->chapters);
    av_dict_free(&s->metadata);
    av_freep(&s->streams);
    av_free(s);
}
['static int read_avserver_streams(OptionsContext *o, AVFormatContext *s, const char *filename)\n{\n    int i, err;\n    AVFormatContext *ic = avformat_alloc_context();\n    ic->interrupt_callback = int_cb;\n    err = avformat_open_input(&ic, filename, NULL, NULL);\n    if (err < 0)\n        return err;\n    for(i=0;i<ic->nb_streams;i++) {\n        AVStream *st;\n        OutputStream *ost;\n        AVCodec *codec;\n        codec = avcodec_find_encoder(ic->streams[i]->codec->codec_id);\n        ost   = new_output_stream(o, s, codec->type);\n        st    = ost->st;\n        memcpy(st, ic->streams[i], sizeof(AVStream));\n        st->info = NULL;\n        avcodec_copy_context(st->codec, ic->streams[i]->codec);\n        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && !ost->stream_copy)\n            choose_sample_fmt(st, codec);\n        else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && !ost->stream_copy)\n            choose_pixel_fmt(st, codec);\n    }\n    av_close_input_file(ic);\n    return 0;\n}', 'void av_close_input_file(AVFormatContext *s)\n{\n    AVIOContext *pb = (s->iformat->flags & AVFMT_NOFILE) || (s->flags & AVFMT_FLAG_CUSTOM_IO) ?\n                       NULL : s->pb;\n    av_close_input_stream(s);\n    if (pb)\n        avio_close(pb);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n    flush_packet_queue(s);\n    if (s->iformat->read_close)\n        s->iformat->read_close(s);\n    avformat_free_context(s);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n    int i;\n    AVStream *st;\n    av_opt_free(s);\n    if (s->iformat && s->iformat->priv_class && s->priv_data)\n        av_opt_free(s->priv_data);\n    for(i=0;i<s->nb_streams;i++) {\n        st = s->streams[i];\n        if (st->parser) {\n            av_parser_close(st->parser);\n            av_free_packet(&st->cur_pkt);\n        }\n        av_dict_free(&st->metadata);\n        av_free(st->index_entries);\n        av_free(st->codec->extradata);\n        av_free(st->codec->subtitle_header);\n        av_free(st->codec);\n        av_free(st->priv_data);\n        av_free(st->info);\n        av_free(st);\n    }\n    for(i=s->nb_programs-1; i>=0; i--) {\n        av_dict_free(&s->programs[i]->metadata);\n        av_freep(&s->programs[i]->stream_index);\n        av_freep(&s->programs[i]);\n    }\n    av_freep(&s->programs);\n    av_freep(&s->priv_data);\n    while(s->nb_chapters--) {\n        av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n        av_free(s->chapters[s->nb_chapters]);\n    }\n    av_freep(&s->chapters);\n    av_dict_free(&s->metadata);\n    av_freep(&s->streams);\n    av_free(s);\n}']