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

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

libavformat/utils.c:2501:5: Call
  2499.     }
  2500. 
  2501.     estimate_timings(ic, old_offset);
            ^
  2502. 
  2503.     compute_chapters_end(ic);

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

libavformat/utils.c:1847:5: Call
      1845. 
      1846.     /* flush packet queue */
      1847.     flush_packet_queue(ic);
                ^
      1848. 
      1849.     for (i = 0; i < ic->nb_streams; i++) {

libavformat/utils.c:1179:5: Call
        1177.     free_packet_buffer(&s->parse_queue,       &s->parse_queue_end);
        1178.     free_packet_buffer(&s->packet_buffer,     &s->packet_buffer_end);
        1179.     free_packet_buffer(&s->raw_packet_buffer, &s->raw_packet_buffer_end);
                  ^
        1180. 
        1181.     s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;

libavformat/utils.c:894:1: Parameter `(*pkt_buf)->pkt.size`
          892. }
          893. 
          894. static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)
               ^
          895. {
          896.     while (*pkt_buf) {

avconv_opt.c:710:9: Call
708.     ret = avformat_find_stream_info(ic, opts);
709.     if (ret < 0) {
710.         av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
             ^
711.         avformat_close_input(&ic);
712.         exit_program(1);

libavutil/log.c:148:1: Parameter `*avcl`
  146.     av_log_default_callback;
  147. 
  148. void av_log(void* avcl, int level, const char *fmt, ...)
       ^
  149. {
  150.     AVClass* avc = avcl ? *(AVClass **) avcl : NULL;

avconv_opt.c:711:9: Call
709.     if (ret < 0) {
710.         av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
711.         avformat_close_input(&ic);
             ^
712.         exit_program(1);
713.     }

libavformat/utils.c:2647:1: Parameter `(*ps)->nb_programs`
  2645. }
  2646. 
  2647. void avformat_close_input(AVFormatContext **ps)
        ^
  2648. {
  2649.     AVFormatContext *s = *ps;

libavformat/utils.c:2662:5: Call
  2660.             s->iformat->read_close(s);
  2661. 
  2662.     avformat_free_context(s);
            ^
  2663. 
  2664.     *ps = NULL;

libavformat/utils.c:2596:1: <LHS trace>
2594. }
2595. 
2596. void avformat_free_context(AVFormatContext *s)
      ^
2597. {
2598.     int i, j;

libavformat/utils.c:2596:1: Parameter `s->nb_programs`
    2594. }
    2595. 
    2596. void avformat_free_context(AVFormatContext *s)
          ^
    2597. {
    2598.     int i, j;

libavformat/utils.c:2629:10: Binary operation: ([0, +oo] - 1):unsigned32 by call to `avformat_close_input` 
    2627.         av_free(st);
    2628.     }
    2629.     for (i = s->nb_programs - 1; i >= 0; i--) {
                   ^
    2630.         av_dict_free(&s->programs[i]->metadata);
    2631.         av_freep(&s->programs[i]->stream_index);

void avformat_free_context(AVFormatContext *s)
{
    int i, j;
    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];
        for (j = 0; j < st->nb_side_data; j++)
            av_freep(&st->side_data[j].data);
        av_freep(&st->side_data);
        st->nb_side_data = 0;
        if (st->parser) {
            av_parser_close(st->parser);
        }
        if (st->attached_pic.data)
            av_free_packet(&st->attached_pic);
        av_dict_free(&st->metadata);
        av_freep(&st->probe_data.buf);
        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_freep(&s->internal);
    av_free(s);
}
['static int open_input_file(OptionsContext *o, const char *filename)\n{\n    InputFile *f;\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    AVDictionary *unused_opts = NULL;\n    AVDictionaryEntry *e = NULL;\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(&o->g->format_opts, "sample_rate", buf, 0);\n    }\n    if (o->nb_audio_channels) {\n        if (file_iformat && file_iformat->priv_class &&\n            av_opt_find(&file_iformat->priv_class, "channels", NULL, 0,\n                        AV_OPT_SEARCH_FAKE_OBJ)) {\n            snprintf(buf, sizeof(buf), "%d",\n                     o->audio_channels[o->nb_audio_channels - 1].u.i);\n            av_dict_set(&o->g->format_opts, "channels", buf, 0);\n        }\n    }\n    if (o->nb_frame_rates) {\n        if (file_iformat && file_iformat->priv_class &&\n            av_opt_find(&file_iformat->priv_class, "framerate", NULL, 0,\n                        AV_OPT_SEARCH_FAKE_OBJ)) {\n            av_dict_set(&o->g->format_opts, "framerate",\n                        o->frame_rates[o->nb_frame_rates - 1].u.str, 0);\n        }\n    }\n    if (o->nb_frame_sizes) {\n        av_dict_set(&o->g->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(&o->g->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, &o->g->format_opts);\n    if (err < 0) {\n        print_error(filename, err);\n        exit_program(1);\n    }\n    assert_avoptions(o->g->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, o->g->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 == AV_NOPTS_VALUE) ? 0 : o->start_time;\n    if (ic->start_time != AV_NOPTS_VALUE)\n        timestamp += ic->start_time;\n    if (o->start_time != AV_NOPTS_VALUE) {\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    GROW_ARRAY(input_files, nb_input_files);\n    f = av_mallocz(sizeof(*f));\n    if (!f)\n        exit_program(1);\n    input_files[nb_input_files - 1] = f;\n    f->ctx        = ic;\n    f->ist_index  = nb_input_streams - ic->nb_streams;\n    f->start_time = o->start_time;\n    f->recording_time = o->recording_time;\n    f->ts_offset  = o->input_ts_offset - (copy_ts ? 0 : timestamp);\n    f->nb_streams = ic->nb_streams;\n    f->rate_emu   = o->rate_emu;\n    f->accurate_seek = o->accurate_seek;\n    unused_opts = strip_specifiers(o->g->codec_opts);\n    for (i = f->ist_index; i < nb_input_streams; i++) {\n        e = NULL;\n        while ((e = av_dict_get(input_streams[i]->opts, "", e,\n                                AV_DICT_IGNORE_SUFFIX)))\n            av_dict_set(&unused_opts, e->key, NULL, 0);\n    }\n    e = NULL;\n    while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {\n        const AVClass *class = avcodec_get_class();\n        const AVOption *option = av_opt_find(&class, e->key, NULL, 0,\n                                             AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);\n        if (!option)\n            continue;\n        if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {\n            av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "\n                   "input file #%d (%s) is not a decoding option.\\n", e->key,\n                   option->help ? option->help : "", nb_input_files - 1,\n                   filename);\n            exit_program(1);\n        }\n        av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "\n               "input file #%d (%s) has not been used for any stream. The most "\n               "likely reason is either wrong type (e.g. a video option with "\n               "no video streams) or that it is a private option of some decoder "\n               "which was not actually used for any stream.\\n", e->key,\n               option->help ? option->help : "", nb_input_files - 1, filename);\n    }\n    av_dict_free(&unused_opts);\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    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        const 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        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,\n                          options ? &options[i] : &thread_opt);\n        if (!has_codec_parameters(st)) {\n            if (codec && !st->codec->codec)\n                avcodec_open2(st->codec, codec,\n                              options ? &options[i] : &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->fps_first_dts = AV_NOPTS_VALUE;\n        ic->streams[i]->info->fps_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))\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->avg_frame_rate.num &&\n                st->codec_info_nb_frames < fps_analyze_framecount &&\n                st->codec->codec_type == AVMEDIA_TYPE_VIDEO)\n                break;\n            if (st->parser && st->parser->parser->split &&\n                !st->codec->extradata)\n                break;\n            if (st->first_dts == AV_NOPTS_VALUE &&\n                (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||\n                 st->codec->codec_type == AVMEDIA_TYPE_AUDIO))\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,\n                   "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 = 0;\n            av_init_packet(&empty_pkt);\n            ret = -1;\n            for (i = 0; i < ic->nb_streams; i++) {\n                st = ic->streams[i];\n                if (st->info->found_decoder == 1) {\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));\n                }\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)) {\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        if (ic->flags & AVFMT_FLAG_NOBUFFER) {\n            pkt = &pkt1;\n        } else {\n            pkt = add_to_pktbuf(&ic->packet_buffer, &pkt1,\n                                &ic->packet_buffer_end);\n            if ((ret = av_dup_packet(pkt)) < 0)\n                goto find_stream_info_err;\n        }\n        read_size += pkt->size;\n        st = ic->streams[pkt->stream_index];\n        if (pkt->dts != AV_NOPTS_VALUE && st->codec_info_nb_frames > 1) {\n            if (st->info->fps_last_dts != AV_NOPTS_VALUE &&\n                st->info->fps_last_dts >= pkt->dts) {\n                av_log(ic, AV_LOG_WARNING,\n                       "Non-increasing DTS in stream %d: packet %d with DTS "\n                       "%"PRId64", packet %d with DTS %"PRId64"\\n",\n                       st->index, st->info->fps_last_dts_idx,\n                       st->info->fps_last_dts, st->codec_info_nb_frames,\n                       pkt->dts);\n                st->info->fps_first_dts =\n                st->info->fps_last_dts  = AV_NOPTS_VALUE;\n            }\n            if (st->info->fps_last_dts != AV_NOPTS_VALUE &&\n                st->info->fps_last_dts_idx > st->info->fps_first_dts_idx &&\n                (pkt->dts - st->info->fps_last_dts) / 1000 >\n                (st->info->fps_last_dts     - st->info->fps_first_dts) /\n                (st->info->fps_last_dts_idx - st->info->fps_first_dts_idx)) {\n                av_log(ic, AV_LOG_WARNING,\n                       "DTS discontinuity in stream %d: packet %d with DTS "\n                       "%"PRId64", packet %d with DTS %"PRId64"\\n",\n                       st->index, st->info->fps_last_dts_idx,\n                       st->info->fps_last_dts, st->codec_info_nb_frames,\n                       pkt->dts);\n                st->info->fps_first_dts =\n                st->info->fps_last_dts  = AV_NOPTS_VALUE;\n            }\n            if (st->info->fps_first_dts == AV_NOPTS_VALUE) {\n                st->info->fps_first_dts     = pkt->dts;\n                st->info->fps_first_dts_idx = st->codec_info_nb_frames;\n            }\n            st->info->fps_last_dts     = pkt->dts;\n            st->info->fps_last_dts_idx = st->codec_info_nb_frames;\n            if (av_rescale_q(pkt->dts - st->info->fps_first_dts, st->time_base,\n                             AV_TIME_BASE_Q) >= ic->max_analyze_duration) {\n                av_log(ic, AV_LOG_WARNING, "max_analyze_duration %d reached\\n",\n                       ic->max_analyze_duration);\n                break;\n            }\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 +\n                                                 FF_INPUT_BUFFER_PADDING_SIZE);\n                if (!st->codec->extradata)\n                    return AVERROR(ENOMEM);\n                memcpy(st->codec->extradata, pkt->data,\n                       st->codec->extradata_size);\n                memset(st->codec->extradata + i, 0,\n                       FF_INPUT_BUFFER_PADDING_SIZE);\n            }\n        }\n        try_decode_frame(st, pkt,\n                         (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->codec_type == AVMEDIA_TYPE_VIDEO) {\n            if (!st->avg_frame_rate.num &&\n                st->info->fps_last_dts != st->info->fps_first_dts) {\n                int64_t delta_dts = st->info->fps_last_dts -\n                                    st->info->fps_first_dts;\n                int delta_packets = st->info->fps_last_dts_idx -\n                                    st->info->fps_first_dts_idx;\n                int best_fps      = 0;\n                double best_error = 0.01;\n                if (delta_dts     >= INT64_MAX / st->time_base.num ||\n                    delta_packets >= INT64_MAX / st->time_base.den ||\n                    delta_dts < 0)\n                    continue;\n                av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,\n                          delta_packets * (int64_t) st->time_base.den,\n                          delta_dts * (int64_t) st->time_base.num, 60000);\n                for (j = 0; j < MAX_STD_TIMEBASES; j++) {\n                    AVRational std_fps = { get_std_framerate(j), 12 * 1001 };\n                    double error       = fabs(av_q2d(st->avg_frame_rate) /\n                                              av_q2d(std_fps) - 1);\n                    if (error < best_error) {\n                        best_error = error;\n                        best_fps   = std_fps.num;\n                    }\n                }\n                if (best_fps)\n                    av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,\n                              best_fps, 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 =\n                    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;\n                break;\n            case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:\n                st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED;\n                break;\n            case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:\n                st->disposition = AV_DISPOSITION_HEARING_IMPAIRED;\n                break;\n            case AV_AUDIO_SERVICE_TYPE_COMMENTARY:\n                st->disposition = AV_DISPOSITION_COMMENT;\n                break;\n            case AV_AUDIO_SERVICE_TYPE_KARAOKE:\n                st->disposition = AV_DISPOSITION_KARAOKE;\n                break;\n            }\n        }\n    }\n    estimate_timings(ic, old_offset);\n    compute_chapters_end(ic);\nfind_stream_info_err:\n    for (i = 0; i < ic->nb_streams; i++) {\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,\n               "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,\n                "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    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,\n                   "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        }\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 = ff_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    }\n}', 'static void flush_packet_queue(AVFormatContext *s)\n{\n    free_packet_buffer(&s->parse_queue,       &s->parse_queue_end);\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->pb;\n    if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||\n        (s->flags & AVFMT_FLAG_CUSTOM_IO))\n        pb = NULL;\n    flush_packet_queue(s);\n    if (s->iformat)\n        if (s->iformat->read_close)\n            s->iformat->read_close(s);\n    avformat_free_context(s);\n    *ps = NULL;\n    avio_close(pb);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n    int i, j;\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        for (j = 0; j < st->nb_side_data; j++)\n            av_freep(&st->side_data[j].data);\n        av_freep(&st->side_data);\n        st->nb_side_data = 0;\n        if (st->parser) {\n            av_parser_close(st->parser);\n        }\n        if (st->attached_pic.data)\n            av_free_packet(&st->attached_pic);\n        av_dict_free(&st->metadata);\n        av_freep(&st->probe_data.buf);\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_freep(&s->internal);\n    av_free(s);\n}']