avconv.c:3326: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned32 by call to `avformat_close_input`.

avconv.c:3323:11: Call
3321.     /* If not enough info to get the stream parameters, we decode the
3322.        first frames to get it. (used in mpeg case for example) */
3323.     ret = avformat_find_stream_info(ic, opts);
                ^
3324.     if (ret < 0) {
3325.         av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);

libavformat/utils.c:2419:5: Call
  2417.     }
  2418. 
  2419.     estimate_timings(ic, old_offset);
            ^
  2420. 
  2421.     compute_chapters_end(ic);

libavformat/utils.c:1956:9: Call
    1954.         file_size && ic->pb->seekable) {
    1955.         /* get accurate estimate from the PTSes */
    1956.         estimate_timings_from_pts(ic, old_offset);
                  ^
    1957.     } else if (has_duration(ic)) {
    1958.         /* at least one component has timings - we use them for all

libavformat/utils.c:1872:5: Call
      1870. 
      1871.     /* flush packet queue */
      1872.     flush_packet_queue(ic);
                ^
      1873. 
      1874.     for (i=0; i<ic->nb_streams; i++) {

libavformat/utils.c:1238:5: Call
        1236. {
        1237.     free_packet_buffer(&s->packet_buffer,     &s->packet_buffer_end);
        1238.     free_packet_buffer(&s->raw_packet_buffer, &s->raw_packet_buffer_end);
                  ^
        1239. 
        1240.     s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;

libavformat/utils.c:1003:1: Parameter `(*pkt_buf)->pkt.size`
          1001. }
          1002. 
          1003. static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)
                ^
          1004. {
          1005.     while (*pkt_buf) {

avconv.c:3325:9: Call
3323.     ret = avformat_find_stream_info(ic, opts);
3324.     if (ret < 0) {
3325.         av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
              ^
3326.         avformat_close_input(&ic);
3327.         exit_program(1);

libavutil/log.c:140:1: Parameter `*avcl`
  138.     av_log_default_callback;
  139. 
  140. void av_log(void* avcl, int level, const char *fmt, ...)
       ^
  141. {
  142.     AVClass* avc = avcl ? *(AVClass **) avcl : NULL;

avconv.c:3326:9: Call
3324.     if (ret < 0) {
3325.         av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
3326.         avformat_close_input(&ic);
              ^
3327.         exit_program(1);
3328.     }

libavformat/utils.c:2592:1: Parameter `(*ps)->nb_programs`
  2590. #endif
  2591. 
  2592. void avformat_close_input(AVFormatContext **ps)
        ^
  2593. {
  2594.     AVFormatContext *s = *ps;

libavformat/utils.c:2600:5: Call
  2598.     if (s->iformat->read_close)
  2599.         s->iformat->read_close(s);
  2600.     avformat_free_context(s);
            ^
  2601.     *ps = NULL;
  2602.     if (pb)

libavformat/utils.c:2541:1: <LHS trace>
2539. }
2540. 
2541. void avformat_free_context(AVFormatContext *s)
      ^
2542. {
2543.     int i;

libavformat/utils.c:2541:1: Parameter `s->nb_programs`
    2539. }
    2540. 
    2541. void avformat_free_context(AVFormatContext *s)
          ^
    2542. {
    2543.     int i;

libavformat/utils.c:2568:9: Binary operation: ([0, +oo] - 1):unsigned32 by call to `avformat_close_input` 
    2566.         av_free(st);
    2567.     }
    2568.     for(i=s->nb_programs-1; i>=0; i--) {
                  ^
    2569.         av_dict_free(&s->programs[i]->metadata);
    2570.         av_freep(&s->programs[i]->stream_index);

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);
        }
        if (st->attached_pic.data)
            av_free_packet(&st->attached_pic);
        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 opt_input_file(OptionsContext *o, const char *opt, const char *filename)\n{\n    AVFormatContext *ic;\n    AVInputFormat *file_iformat = NULL;\n    int err, i, ret;\n    int64_t timestamp;\n    uint8_t buf[128];\n    AVDictionary **opts;\n    int orig_nb_streams;\n    if (o->format) {\n        if (!(file_iformat = av_find_input_format(o->format))) {\n            av_log(NULL, AV_LOG_FATAL, "Unknown input format: \'%s\'\\n", o->format);\n            exit_program(1);\n        }\n    }\n    if (!strcmp(filename, "-"))\n        filename = "pipe:";\n    using_stdin |= !strncmp(filename, "pipe:", 5) ||\n                    !strcmp(filename, "/dev/stdin");\n    ic = avformat_alloc_context();\n    if (!ic) {\n        print_error(filename, AVERROR(ENOMEM));\n        exit_program(1);\n    }\n    if (o->nb_audio_sample_rate) {\n        snprintf(buf, sizeof(buf), "%d", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i);\n        av_dict_set(&format_opts, "sample_rate", buf, 0);\n    }\n    if (o->nb_audio_channels) {\n        snprintf(buf, sizeof(buf), "%d", o->audio_channels[o->nb_audio_channels - 1].u.i);\n        av_dict_set(&format_opts, "channels", buf, 0);\n    }\n    if (o->nb_frame_rates) {\n        av_dict_set(&format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0);\n    }\n    if (o->nb_frame_sizes) {\n        av_dict_set(&format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);\n    }\n    if (o->nb_frame_pix_fmts)\n        av_dict_set(&format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);\n    ic->flags |= AVFMT_FLAG_NONBLOCK;\n    ic->interrupt_callback = int_cb;\n    err = avformat_open_input(&ic, filename, file_iformat, &format_opts);\n    if (err < 0) {\n        print_error(filename, err);\n        exit_program(1);\n    }\n    assert_avoptions(format_opts);\n    for (i = 0; i < ic->nb_streams; i++)\n        choose_decoder(o, ic, ic->streams[i]);\n    opts = setup_find_stream_info_opts(ic, codec_opts);\n    orig_nb_streams = ic->nb_streams;\n    ret = avformat_find_stream_info(ic, opts);\n    if (ret < 0) {\n        av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\\n", filename);\n        avformat_close_input(&ic);\n        exit_program(1);\n    }\n    timestamp = o->start_time;\n    if (ic->start_time != AV_NOPTS_VALUE)\n        timestamp += ic->start_time;\n    if (o->start_time != 0) {\n        ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);\n        if (ret < 0) {\n            av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\\n",\n                   filename, (double)timestamp / AV_TIME_BASE);\n        }\n    }\n    add_input_streams(o, ic);\n    av_dump_format(ic, nb_input_files, filename, 0);\n    input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);\n    input_files[nb_input_files - 1].ctx        = ic;\n    input_files[nb_input_files - 1].ist_index  = nb_input_streams - ic->nb_streams;\n    input_files[nb_input_files - 1].ts_offset  = o->input_ts_offset - (copy_ts ? 0 : timestamp);\n    input_files[nb_input_files - 1].nb_streams = ic->nb_streams;\n    input_files[nb_input_files - 1].rate_emu   = o->rate_emu;\n    for (i = 0; i < o->nb_dump_attachment; i++) {\n        int j;\n        for (j = 0; j < ic->nb_streams; j++) {\n            AVStream *st = ic->streams[j];\n            if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)\n                dump_attachment(st, o->dump_attachment[i].u.str);\n        }\n    }\n    for (i = 0; i < orig_nb_streams; i++)\n        av_dict_free(&opts[i]);\n    av_freep(&opts);\n    reset_options(o);\n    return 0;\n}', 'int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)\n{\n    int i, count, ret, read_size, j;\n    AVStream *st;\n    AVPacket pkt1, *pkt;\n    int64_t old_offset = avio_tell(ic->pb);\n    int orig_nb_streams = ic->nb_streams;\n    for(i=0;i<ic->nb_streams;i++) {\n        AVCodec *codec;\n        AVDictionary *thread_opt = NULL;\n        st = ic->streams[i];\n        if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE)) {\n            st->parser = av_parser_init(st->codec->codec_id);\n            if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){\n                st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;\n            }\n        }\n        codec = st->codec->codec ? st->codec->codec :\n                                   avcodec_find_decoder(st->codec->codec_id);\n        av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0);\n        if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE\n            && codec && !st->codec->codec)\n            avcodec_open2(st->codec, codec, options ? &options[i]\n                              : &thread_opt);\n        if(!has_codec_parameters(st->codec)){\n            if (codec && !st->codec->codec)\n                avcodec_open2(st->codec, codec, options ? &options[i]\n                              : &thread_opt);\n        }\n        if (!options)\n            av_dict_free(&thread_opt);\n    }\n    for (i=0; i<ic->nb_streams; i++) {\n        ic->streams[i]->info->last_dts = AV_NOPTS_VALUE;\n    }\n    count = 0;\n    read_size = 0;\n    for(;;) {\n        if (ff_check_interrupt(&ic->interrupt_callback)){\n            ret= AVERROR_EXIT;\n            av_log(ic, AV_LOG_DEBUG, "interrupted\\n");\n            break;\n        }\n        for(i=0;i<ic->nb_streams;i++) {\n            int fps_analyze_framecount = 20;\n            st = ic->streams[i];\n            if (!has_codec_parameters(st->codec))\n                break;\n            if (av_q2d(st->time_base) > 0.0005)\n                fps_analyze_framecount *= 2;\n            if (ic->fps_probe_size >= 0)\n                fps_analyze_framecount = ic->fps_probe_size;\n            if(   tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num)\n               && st->info->duration_count < fps_analyze_framecount\n               && st->codec->codec_type == AVMEDIA_TYPE_VIDEO)\n                break;\n            if(st->parser && st->parser->parser->split && !st->codec->extradata)\n                break;\n            if(st->first_dts == AV_NOPTS_VALUE)\n                break;\n        }\n        if (i == ic->nb_streams) {\n            if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) {\n                ret = count;\n                av_log(ic, AV_LOG_DEBUG, "All info found\\n");\n                break;\n            }\n        }\n        if (read_size >= ic->probesize) {\n            ret = count;\n            av_log(ic, AV_LOG_DEBUG, "Probe buffer size limit %d reached\\n", ic->probesize);\n            break;\n        }\n        ret = read_frame_internal(ic, &pkt1);\n        if (ret == AVERROR(EAGAIN))\n            continue;\n        if (ret < 0) {\n            AVPacket empty_pkt = { 0 };\n            int err;\n            av_init_packet(&empty_pkt);\n            ret = -1;\n            for(i=0;i<ic->nb_streams;i++) {\n                st = ic->streams[i];\n                do {\n                    err = try_decode_frame(st, &empty_pkt,\n                                           (options && i < orig_nb_streams) ?\n                                           &options[i] : NULL);\n                } while (err > 0 && !has_codec_parameters(st->codec));\n                if (err < 0) {\n                    av_log(ic, AV_LOG_WARNING,\n                           "decoding for stream %d failed\\n", st->index);\n                } else if (!has_codec_parameters(st->codec)){\n                    char buf[256];\n                    avcodec_string(buf, sizeof(buf), st->codec, 0);\n                    av_log(ic, AV_LOG_WARNING,\n                           "Could not find codec parameters (%s)\\n", buf);\n                } else {\n                    ret = 0;\n                }\n            }\n            break;\n        }\n        pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end);\n        if ((ret = av_dup_packet(pkt)) < 0)\n            goto find_stream_info_err;\n        read_size += pkt->size;\n        st = ic->streams[pkt->stream_index];\n        if (st->codec_info_nb_frames>1) {\n            if (st->time_base.den > 0 && av_rescale_q(st->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) {\n                av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\\n");\n                break;\n            }\n            st->info->codec_info_duration += pkt->duration;\n        }\n        {\n            int64_t last = st->info->last_dts;\n            if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && pkt->dts > last){\n                int64_t duration= pkt->dts - last;\n                double dur= duration * av_q2d(st->time_base);\n                if (st->info->duration_count < 2)\n                    memset(st->info->duration_error, 0, sizeof(st->info->duration_error));\n                for (i=1; i<FF_ARRAY_ELEMS(st->info->duration_error); i++) {\n                    int framerate= get_std_framerate(i);\n                    int ticks= lrintf(dur*framerate/(1001*12));\n                    double error = dur - (double)ticks*1001*12 / framerate;\n                    st->info->duration_error[i] += error*error;\n                }\n                st->info->duration_count++;\n                if (st->info->duration_count > 3)\n                    st->info->duration_gcd = av_gcd(st->info->duration_gcd, duration);\n            }\n            if (last == AV_NOPTS_VALUE || st->info->duration_count <= 1)\n                st->info->last_dts = pkt->dts;\n        }\n        if(st->parser && st->parser->parser->split && !st->codec->extradata){\n            int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);\n            if (i > 0 && i < FF_MAX_EXTRADATA_SIZE) {\n                st->codec->extradata_size= i;\n                st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);\n                if (!st->codec->extradata)\n                    return AVERROR(ENOMEM);\n                memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size);\n                memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n            }\n        }\n        try_decode_frame(st, pkt, (options && i < orig_nb_streams ) ? &options[i] : NULL);\n        st->codec_info_nb_frames++;\n        count++;\n    }\n    for(i=0;i<ic->nb_streams;i++) {\n        st = ic->streams[i];\n        avcodec_close(st->codec);\n    }\n    for(i=0;i<ic->nb_streams;i++) {\n        st = ic->streams[i];\n        if (st->codec_info_nb_frames>2 && !st->avg_frame_rate.num && st->info->codec_info_duration)\n            av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,\n                     (st->codec_info_nb_frames-2)*(int64_t)st->time_base.den,\n                      st->info->codec_info_duration*(int64_t)st->time_base.num, 60000);\n        if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n            if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > 1 && !st->r_frame_rate.num)\n                av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->info->duration_gcd, INT_MAX);\n            if (st->info->duration_count && !st->r_frame_rate.num\n               && tb_unreliable(st->codec)  ){\n                int num = 0;\n                double best_error= 2*av_q2d(st->time_base);\n                best_error = best_error*best_error*st->info->duration_count*1000*12*30;\n                for (j=1; j<FF_ARRAY_ELEMS(st->info->duration_error); j++) {\n                    double error = st->info->duration_error[j] * get_std_framerate(j);\n                    if(error < best_error){\n                        best_error= error;\n                        num = get_std_framerate(j);\n                    }\n                }\n                if (num && (!st->r_frame_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(st->r_frame_rate)))\n                    av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX);\n            }\n        }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {\n            if(!st->codec->bits_per_coded_sample)\n                st->codec->bits_per_coded_sample= av_get_bits_per_sample(st->codec->codec_id);\n            switch (st->codec->audio_service_type) {\n            case AV_AUDIO_SERVICE_TYPE_EFFECTS:\n                st->disposition = AV_DISPOSITION_CLEAN_EFFECTS;    break;\n            case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:\n                st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED;  break;\n            case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:\n                st->disposition = AV_DISPOSITION_HEARING_IMPAIRED; break;\n            case AV_AUDIO_SERVICE_TYPE_COMMENTARY:\n                st->disposition = AV_DISPOSITION_COMMENT;          break;\n            case AV_AUDIO_SERVICE_TYPE_KARAOKE:\n                st->disposition = AV_DISPOSITION_KARAOKE;          break;\n            }\n        }\n    }\n    estimate_timings(ic, old_offset);\n    compute_chapters_end(ic);\n#if 0\n    for(i=0;i<ic->nb_streams;i++) {\n        st = ic->streams[i];\n        if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n            if(b-frames){\n                ppktl = &ic->packet_buffer;\n                while(ppkt1){\n                    if(ppkt1->stream_index != i)\n                        continue;\n                    if(ppkt1->pkt->dts < 0)\n                        break;\n                    if(ppkt1->pkt->pts != AV_NOPTS_VALUE)\n                        break;\n                    ppkt1->pkt->dts -= delta;\n                    ppkt1= ppkt1->next;\n                }\n                if(ppkt1)\n                    continue;\n                st->cur_dts -= delta;\n            }\n        }\n    }\n#endif\n find_stream_info_err:\n    for (i=0; i < ic->nb_streams; i++) {\n        if (ic->streams[i]->codec)\n            ic->streams[i]->codec->thread_count = 0;\n        av_freep(&ic->streams[i]->info);\n    }\n    return ret;\n}', 'static void estimate_timings(AVFormatContext *ic, int64_t old_offset)\n{\n    int64_t file_size;\n    if (ic->iformat->flags & AVFMT_NOFILE) {\n        file_size = 0;\n    } else {\n        file_size = avio_size(ic->pb);\n        file_size = FFMAX(0, file_size);\n    }\n    if ((!strcmp(ic->iformat->name, "mpeg") ||\n         !strcmp(ic->iformat->name, "mpegts")) &&\n        file_size && ic->pb->seekable) {\n        estimate_timings_from_pts(ic, old_offset);\n    } else if (has_duration(ic)) {\n        fill_all_stream_timings(ic);\n    } else {\n        av_log(ic, AV_LOG_WARNING, "Estimating duration from bitrate, this may be inaccurate\\n");\n        estimate_timings_from_bit_rate(ic);\n    }\n    update_stream_timings(ic);\n    {\n        int i;\n        AVStream av_unused *st;\n        for(i = 0;i < ic->nb_streams; i++) {\n            st = ic->streams[i];\n            av_dlog(ic, "%d: start_time: %0.3f duration: %0.3f\\n", i,\n                    (double) st->start_time / AV_TIME_BASE,\n                    (double) st->duration   / AV_TIME_BASE);\n        }\n        av_dlog(ic, "stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\\n",\n                (double) ic->start_time / AV_TIME_BASE,\n                (double) ic->duration   / AV_TIME_BASE,\n                ic->bit_rate / 1000);\n    }\n}', 'static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)\n{\n    AVPacket pkt1, *pkt = &pkt1;\n    AVStream *st;\n    int read_size, i, ret;\n    int64_t end_time;\n    int64_t filesize, offset, duration;\n    int retry=0;\n    ic->cur_st = NULL;\n    flush_packet_queue(ic);\n    for (i=0; i<ic->nb_streams; i++) {\n        st = ic->streams[i];\n        if (st->start_time == AV_NOPTS_VALUE && st->first_dts == AV_NOPTS_VALUE)\n            av_log(st->codec, AV_LOG_WARNING, "start time is not set in estimate_timings_from_pts\\n");\n        if (st->parser) {\n            av_parser_close(st->parser);\n            st->parser= NULL;\n            av_free_packet(&st->cur_pkt);\n        }\n    }\n    filesize = ic->pb ? avio_size(ic->pb) : 0;\n    end_time = AV_NOPTS_VALUE;\n    do{\n        offset = filesize - (DURATION_MAX_READ_SIZE<<retry);\n        if (offset < 0)\n            offset = 0;\n        avio_seek(ic->pb, offset, SEEK_SET);\n        read_size = 0;\n        for(;;) {\n            if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0)))\n                break;\n            do {\n                ret = av_read_packet(ic, pkt);\n            } while(ret == AVERROR(EAGAIN));\n            if (ret != 0)\n                break;\n            read_size += pkt->size;\n            st = ic->streams[pkt->stream_index];\n            if (pkt->pts != AV_NOPTS_VALUE &&\n                (st->start_time != AV_NOPTS_VALUE ||\n                 st->first_dts  != AV_NOPTS_VALUE)) {\n                duration = end_time = pkt->pts;\n                if (st->start_time != AV_NOPTS_VALUE)\n                    duration -= st->start_time;\n                else\n                    duration -= st->first_dts;\n                if (duration < 0)\n                    duration += 1LL<<st->pts_wrap_bits;\n                if (duration > 0) {\n                    if (st->duration == AV_NOPTS_VALUE || st->duration < duration)\n                        st->duration = duration;\n                }\n            }\n            av_free_packet(pkt);\n        }\n    }while(   end_time==AV_NOPTS_VALUE\n           && filesize > (DURATION_MAX_READ_SIZE<<retry)\n           && ++retry <= DURATION_MAX_RETRY);\n    fill_all_stream_timings(ic);\n    avio_seek(ic->pb, old_offset, SEEK_SET);\n    for (i=0; i<ic->nb_streams; i++) {\n        st= ic->streams[i];\n        st->cur_dts= st->first_dts;\n        st->last_IP_pts = AV_NOPTS_VALUE;\n        st->reference_dts = AV_NOPTS_VALUE;\n    }\n}', 'static void flush_packet_queue(AVFormatContext *s)\n{\n    free_packet_buffer(&s->packet_buffer,     &s->packet_buffer_end);\n    free_packet_buffer(&s->raw_packet_buffer, &s->raw_packet_buffer_end);\n    s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;\n}', 'static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)\n{\n    while (*pkt_buf) {\n        AVPacketList *pktl = *pkt_buf;\n        *pkt_buf = pktl->next;\n        av_free_packet(&pktl->pkt);\n        av_freep(&pktl);\n    }\n    *pkt_buf_end = NULL;\n}', 'void av_log(void* avcl, int level, const char *fmt, ...)\n{\n    AVClass* avc = avcl ? *(AVClass **) avcl : NULL;\n    va_list vl;\n    va_start(vl, fmt);\n    if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&\n        avc->log_level_offset_offset && level >= AV_LOG_FATAL)\n        level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset);\n    av_vlog(avcl, level, fmt, vl);\n    va_end(vl);\n}', 'void avformat_close_input(AVFormatContext **ps)\n{\n    AVFormatContext *s = *ps;\n    AVIOContext *pb = (s->iformat->flags & AVFMT_NOFILE) || (s->flags & AVFMT_FLAG_CUSTOM_IO) ?\n                       NULL : s->pb;\n    flush_packet_queue(s);\n    if (s->iformat->read_close)\n        s->iformat->read_close(s);\n    avformat_free_context(s);\n    *ps = NULL;\n    if (pb)\n        avio_close(pb);\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        if (st->attached_pic.data)\n            av_free_packet(&st->attached_pic);\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}']