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);
}
['int Configure(void **ctxp, int argc, char *argv[])\n{\n    ContextInfo *ci;\n    int c;\n    int tmp = 0;\n    if (0 == (*ctxp = av_mallocz(sizeof(ContextInfo)))) return -1;\n    ci = (ContextInfo *) *ctxp;\n    optind = 1;\n    ci->thrR = 0x80;\n    ci->thrG = 0x80;\n    ci->thrB = 0x80;\n    while ((c = getopt(argc, argv, "f:m:t:")) > 0) {\n        switch (c) {\n            case \'f\':\n                strncpy(ci->filename, optarg, 1999);\n                ci->filename[1999] = 0;\n                break;\n            case \'m\':\n                ci->mode = atoi(optarg);\n                break;\n            case \'t\':\n                if (1 != sscanf(optarg, "%x", &tmp)) {\n                    av_log(NULL, AV_LOG_ERROR, "Watermark: argument to -t must be a 6 digit hex number\\n");\n                    return -1;\n                }\n                ci->thrR = (tmp >> 16) & 0xff;\n                ci->thrG = (tmp >> 8) & 0xff;\n                ci->thrB = (tmp >> 0) & 0xff;\n                break;\n            default:\n                av_log(NULL, AV_LOG_ERROR, "Watermark: Unrecognized argument \'%s\'\\n", argv[optind]);\n                return -1;\n        }\n    }\n    if (0 == ci->filename[0]) {\n        av_log(NULL, AV_LOG_ERROR, "Watermark: There is no filename specified.\\n");\n        return -1;\n    }\n    av_register_all();\n    return get_watermark_picture(ci, 0);\n}', 'int get_watermark_picture(ContextInfo *ci, int cleanup)\n{\n    if (1 == ci->is_done && 0 == cleanup) return 0;\n    if (0 == ci->pFrameRGB &&\n        0 == cleanup)\n    {\n        if (av_open_input_file(&ci->pFormatCtx, ci->filename, NULL, 0, NULL) != 0) {\n            ci->i = strlen(ci->filename);\n            if (0 == ci->i) {\n                av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() No filename to watermark vhook\\n");\n                return -1;\n            }\n            while (ci->i > 0) {\n                if (ci->filename[ci->i] == \'.\') {\n                    ci->i++;\n                    break;\n                }\n                ci->i--;\n            }\n               ci->p_ext = &(ci->filename[ci->i]);\n            ci->file_iformat = av_find_input_format (ci->p_ext);\n            if (0 == ci->file_iformat) {\n                av_log(NULL, AV_LOG_INFO, "get_watermark_picture() attempt to use image2 for [%s]\\n", ci->p_ext);\n                ci->file_iformat = av_find_input_format ("image2");\n            }\n            if (0 == ci->file_iformat) {\n                av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Really failed to find iformat [%s]\\n", ci->p_ext);\n                return -1;\n            }\n            if (av_open_input_file(&ci->pFormatCtx, ci->filename, ci->file_iformat, 0, NULL)!=0) {\n                av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to open input file [%s]\\n", ci->filename);\n                return -1;\n            }\n        }\n        if(av_find_stream_info(ci->pFormatCtx)<0) {\n            av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to find stream info\\n");\n            return -1;\n        }\n        ci->videoStream=-1;\n        for(ci->i = 0; ci->i < ci->pFormatCtx->nb_streams; ci->i++)\n            if(ci->pFormatCtx->streams[ci->i]->codec->codec_type==CODEC_TYPE_VIDEO)\n            {\n                ci->videoStream = ci->i;\n                break;\n            }\n        if(ci->videoStream == -1) {\n            av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to find any video stream\\n");\n            return -1;\n        }\n        ci->st = ci->pFormatCtx->streams[ci->videoStream];\n        ci->x_size = ci->st->codec->width;\n        ci->y_size = ci->st->codec->height;\n        ci->pCodecCtx = ci->pFormatCtx->streams[ci->videoStream]->codec;\n        ci->pCodec = avcodec_find_decoder(ci->pCodecCtx->codec_id);\n        if(ci->pCodec == NULL) {\n            av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to find any codec\\n");\n            return -1;\n        }\n        if(avcodec_open(ci->pCodecCtx, ci->pCodec)<0) {\n            av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to open codec\\n");\n            return -1;\n        }\n        if (ci->pCodecCtx->time_base.den>1000 && ci->pCodecCtx->time_base.num==1)\n            ci->pCodecCtx->time_base.num=1000;\n        ci->pFrame = avcodec_alloc_frame();\n        ci->pFrameRGB=avcodec_alloc_frame();\n        if(ci->pFrameRGB==NULL) {\n            av_log(NULL, AV_LOG_ERROR, "get_watermark_picture() Failed to alloc pFrameRGB\\n");\n            return -1;\n        }\n        ci->numBytes = avpicture_get_size(PIX_FMT_RGB32, ci->pCodecCtx->width,\n            ci->pCodecCtx->height);\n        ci->buffer = av_malloc(ci->numBytes);\n        avpicture_fill((AVPicture *)ci->pFrameRGB, ci->buffer, PIX_FMT_RGB32,\n            ci->pCodecCtx->width, ci->pCodecCtx->height);\n    }\n    if (0 == cleanup)\n    {\n        while(av_read_frame(ci->pFormatCtx, &ci->packet)>=0)\n        {\n            if(ci->packet.stream_index == ci->videoStream)\n            {\n                avcodec_decode_video(ci->pCodecCtx, ci->pFrame, &ci->frameFinished,\n                    ci->packet.data, ci->packet.size);\n                if(ci->frameFinished)\n                {\n                    ci->watermark_convert_ctx =\n                        sws_getCachedContext(ci->watermark_convert_ctx,\n                            ci->pCodecCtx->width, ci->pCodecCtx->height, ci->pCodecCtx->pix_fmt,\n                            ci->pCodecCtx->width, ci->pCodecCtx->height, PIX_FMT_RGB32,\n                            sws_flags, NULL, NULL, NULL);\n                    if (ci->watermark_convert_ctx == NULL) {\n                        av_log(NULL, AV_LOG_ERROR,\n                              "Cannot initialize the watermark conversion context\\n");\n                        return -1;\n                    }\n                    sws_scale(ci->watermark_convert_ctx,\n                             ci->pFrame->data, ci->pFrame->linesize, 0, ci->pCodecCtx->height,\n                             ci->pFrameRGB->data, ci->pFrameRGB->linesize);\n                    return 0;\n                }\n            }\n            av_free_packet(&ci->packet);\n        }\n        ci->is_done = 1;\n        return 0;\n    }\n    if (0 != cleanup)\n    {\n        av_freep(&ci->buffer);\n        av_freep(&ci->pFrameRGB);\n        if (0 != ci->pCodecCtx) {\n            avcodec_close(ci->pCodecCtx);\n            ci->pCodecCtx = 0;\n        }\n        if (0 != ci->pFormatCtx) {\n            av_close_input_file(ci->pFormatCtx);\n            ci->pFormatCtx = 0;\n        }\n        ci->is_done = 0;\n    }\n    return 0;\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}']