void av_close_input_stream(AVFormatContext *s)
{
    int i;
    AVStream *st;
    if (s->cur_st && s->cur_st->parser)
        av_free_packet(&s->cur_pkt);
    if (s->iformat->read_close)
        s->iformat->read_close(s);
    for(i=0;i<s->nb_streams;i++) {
        st = s->streams[i];
        if (st->parser) {
            av_parser_close(st->parser);
        }
        av_free(st->index_entries);
        av_free(st->codec->extradata);
        av_free(st->codec);
        av_free(st->filename);
        av_free(st);
    }
    for(i=s->nb_programs-1; i>=0; i--) {
        av_freep(&s->programs[i]->provider_name);
        av_freep(&s->programs[i]->name);
        av_freep(&s->programs[i]->stream_index);
        av_freep(&s->programs[i]);
    }
    flush_packet_queue(s);
    av_freep(&s->priv_data);
    av_free(s);
}
['static void build_feed_streams(void)\n{\n    FFStream *stream, *feed;\n    int i;\n    for(stream = first_stream; stream != NULL; stream = stream->next) {\n        feed = stream->feed;\n        if (feed) {\n            if (!stream->is_feed) {\n                for(i=0;i<stream->nb_streams;i++)\n                    stream->feed_streams[i] = add_av_stream(feed, stream->streams[i]);\n            }\n        }\n    }\n    for(stream = first_stream; stream != NULL; stream = stream->next) {\n        feed = stream->feed;\n        if (feed) {\n            if (stream->is_feed) {\n                for(i=0;i<stream->nb_streams;i++)\n                    stream->feed_streams[i] = i;\n            }\n        }\n    }\n    for(feed = first_feed; feed != NULL; feed = feed->next_feed) {\n        int fd;\n        if (url_exist(feed->feed_filename)) {\n            AVFormatContext *s;\n            int matches = 0;\n            if (av_open_input_file(&s, feed->feed_filename, NULL, FFM_PACKET_SIZE, NULL) >= 0) {\n                if (s->nb_streams == feed->nb_streams) {\n                    matches = 1;\n                    for(i=0;i<s->nb_streams;i++) {\n                        AVStream *sf, *ss;\n                        sf = feed->streams[i];\n                        ss = s->streams[i];\n                        if (sf->index != ss->index ||\n                            sf->id != ss->id) {\n                            printf("Index & Id do not match for stream %d (%s)\\n",\n                                   i, feed->feed_filename);\n                            matches = 0;\n                        } else {\n                            AVCodecContext *ccf, *ccs;\n                            ccf = sf->codec;\n                            ccs = ss->codec;\n#define CHECK_CODEC(x)  (ccf->x != ccs->x)\n                            if (CHECK_CODEC(codec) || CHECK_CODEC(codec_type)) {\n                                printf("Codecs do not match for stream %d\\n", i);\n                                matches = 0;\n                            } else if (CHECK_CODEC(bit_rate) || CHECK_CODEC(flags)) {\n                                printf("Codec bitrates do not match for stream %d\\n", i);\n                                matches = 0;\n                            } else if (ccf->codec_type == CODEC_TYPE_VIDEO) {\n                                if (CHECK_CODEC(time_base.den) ||\n                                    CHECK_CODEC(time_base.num) ||\n                                    CHECK_CODEC(width) ||\n                                    CHECK_CODEC(height)) {\n                                    printf("Codec width, height and framerate do not match for stream %d\\n", i);\n                                    matches = 0;\n                                }\n                            } else if (ccf->codec_type == CODEC_TYPE_AUDIO) {\n                                if (CHECK_CODEC(sample_rate) ||\n                                    CHECK_CODEC(channels) ||\n                                    CHECK_CODEC(frame_size)) {\n                                    printf("Codec sample_rate, channels, frame_size do not match for stream %d\\n", i);\n                                    matches = 0;\n                                }\n                            } else {\n                                printf("Unknown codec type\\n");\n                                matches = 0;\n                            }\n                        }\n                        if (!matches)\n                            break;\n                    }\n                } else\n                    printf("Deleting feed file \'%s\' as stream counts differ (%d != %d)\\n",\n                        feed->feed_filename, s->nb_streams, feed->nb_streams);\n                av_close_input_file(s);\n            } else\n                printf("Deleting feed file \'%s\' as it appears to be corrupt\\n",\n                        feed->feed_filename);\n            if (!matches) {\n                if (feed->readonly) {\n                    printf("Unable to delete feed file \'%s\' as it is marked readonly\\n",\n                        feed->feed_filename);\n                    exit(1);\n                }\n                unlink(feed->feed_filename);\n            }\n        }\n        if (!url_exist(feed->feed_filename)) {\n            AVFormatContext s1, *s = &s1;\n            if (feed->readonly) {\n                printf("Unable to create feed file \'%s\' as it is marked readonly\\n",\n                    feed->feed_filename);\n                exit(1);\n            }\n            if (url_fopen(&s->pb, feed->feed_filename, URL_WRONLY) < 0) {\n                fprintf(stderr, "Could not open output feed file \'%s\'\\n",\n                        feed->feed_filename);\n                exit(1);\n            }\n            s->oformat = feed->fmt;\n            s->nb_streams = feed->nb_streams;\n            for(i=0;i<s->nb_streams;i++) {\n                AVStream *st;\n                st = feed->streams[i];\n                s->streams[i] = st;\n            }\n            av_set_parameters(s, NULL);\n            if (av_write_header(s) < 0) {\n                fprintf(stderr, "Container doesn\'t supports the required parameters\\n");\n                exit(1);\n            }\n            av_freep(&s->priv_data);\n            url_fclose(s->pb);\n        }\n        fd = open(feed->feed_filename, O_RDONLY);\n        if (fd < 0) {\n            fprintf(stderr, "Could not open output feed file \'%s\'\\n",\n                    feed->feed_filename);\n            exit(1);\n        }\n        feed->feed_write_index = ffm_read_write_index(fd);\n        feed->feed_size = lseek(fd, 0, SEEK_END);\n        if (feed->feed_max_size && feed->feed_max_size < feed->feed_size)\n            feed->feed_max_size = feed->feed_size;\n        close(fd);\n    }\n}', 'void av_close_input_file(AVFormatContext *s)\n{\n    ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb;\n    av_close_input_stream(s);\n    if (pb)\n        url_fclose(pb);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n    int i;\n    AVStream *st;\n    if (s->cur_st && s->cur_st->parser)\n        av_free_packet(&s->cur_pkt);\n    if (s->iformat->read_close)\n        s->iformat->read_close(s);\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        }\n        av_free(st->index_entries);\n        av_free(st->codec->extradata);\n        av_free(st->codec);\n        av_free(st->filename);\n        av_free(st);\n    }\n    for(i=s->nb_programs-1; i>=0; i--) {\n        av_freep(&s->programs[i]->provider_name);\n        av_freep(&s->programs[i]->name);\n        av_freep(&s->programs[i]->stream_index);\n        av_freep(&s->programs[i]);\n    }\n    flush_packet_queue(s);\n    av_freep(&s->priv_data);\n    av_free(s);\n}']