if(st->codec.codec_id == CODEC_ID_RAWVIDEO && !st->codec.codec_tag) st->codec.codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec.pix_fmt);
int av_find_stream_info(AVFormatContext *ic){    int i, count, ret, read_size;    AVStream *st;    AVPacket pkt1, *pkt;    AVPacketList *pktl=NULL, **ppktl;    count = 0;    read_size = 0;    ppktl = &ic->packet_buffer;    for(;;) {        /* check if one codec still needs to be handled */        for(i=0;i<ic->nb_streams;i++) {            st = ic->streams[i];            if (!has_codec_parameters(&st->codec))                break;        }        if (i == ic->nb_streams) {            /* NOTE: if the format has no header, then we need to read               some packets to get most of the streams, so we cannot               stop here */            if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) {                /* if we found the info for all the codecs, we can stop */                ret = count;                break;            }        } else {            /* we did not get all the codec info, but we read too much data */            if (read_size >= MAX_READ_SIZE) {                ret = count;                break;            }        }        /* NOTE: a new stream can be added there if no header in file           (AVFMTCTX_NOHEADER) */        ret = av_read_frame_internal(ic, &pkt1);        if (ret < 0) {            /* EOF or error */            ret = -1; /* we could not have all the codec parameters before EOF */            if ((ic->ctx_flags & AVFMTCTX_NOHEADER) &&                i == ic->nb_streams)                ret = 0;            break;        }        pktl = av_mallocz(sizeof(AVPacketList));        if (!pktl) {            ret = AVERROR_NOMEM;            break;        }        /* add the packet in the buffered packet list */        *ppktl = pktl;        ppktl = &pktl->next;        pkt = &pktl->pkt;        *pkt = pkt1;                /* duplicate the packet */        if (av_dup_packet(pkt) < 0) {                ret = AVERROR_NOMEM;                break;        }        read_size += pkt->size;        st = ic->streams[pkt->stream_index];        st->codec_info_duration += pkt->duration;        if (pkt->duration != 0)            st->codec_info_nb_frames++;        /* if still no information, we try to open the codec and to           decompress the frame. We try to avoid that in most cases as           it takes longer and uses more memory. For MPEG4, we need to           decompress for Quicktime. */        if (!has_codec_parameters(&st->codec) &&            (st->codec.codec_id == CODEC_ID_FLV1 ||             st->codec.codec_id == CODEC_ID_H264 ||             st->codec.codec_id == CODEC_ID_H263 ||             st->codec.codec_id == CODEC_ID_VORBIS ||             st->codec.codec_id == CODEC_ID_MJPEG ||             (st->codec.codec_id == CODEC_ID_MPEG4 && !st->need_parsing)))            try_decode_frame(st, pkt->data, pkt->size);                if (st->codec_info_duration >= MAX_STREAM_DURATION) {            break;        }        count++;    }    /* set real frame rate info */    for(i=0;i<ic->nb_streams;i++) {        st = ic->streams[i];        if (st->codec.codec_type == CODEC_TYPE_VIDEO) {            /* compute the real frame rate for telecine */            if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO ||                 st->codec.codec_id == CODEC_ID_MPEG2VIDEO) &&                st->codec.sub_id == 2) {                if (st->codec_info_nb_frames >= 20) {                    float coded_frame_rate, est_frame_rate;                    est_frame_rate = ((double)st->codec_info_nb_frames * AV_TIME_BASE) /                         (double)st->codec_info_duration ;                    coded_frame_rate = (double)st->codec.frame_rate /                        (double)st->codec.frame_rate_base;#if 0                    printf("telecine: coded_frame_rate=%0.3f est_frame_rate=%0.3f\n",                            coded_frame_rate, est_frame_rate);#endif                    /* if we detect that it could be a telecine, we                       signal it. It would be better to do it at a                       higher level as it can change in a film */                    if (coded_frame_rate >= 24.97 &&                         (est_frame_rate >= 23.5 && est_frame_rate < 24.5)) {                        st->r_frame_rate = 24024;                        st->r_frame_rate_base = 1001;                    }                }            }            /* if no real frame rate, use the codec one */            if (!st->r_frame_rate){                st->r_frame_rate      = st->codec.frame_rate;                st->r_frame_rate_base = st->codec.frame_rate_base;            }        }    }    av_estimate_timings(ic);#if 0    /* correct DTS for b frame streams with no timestamps */    for(i=0;i<ic->nb_streams;i++) {        st = ic->streams[i];        if (st->codec.codec_type == CODEC_TYPE_VIDEO) {            if(b-frames){                ppktl = &ic->packet_buffer;                while(ppkt1){                    if(ppkt1->stream_index != i)                        continue;                    if(ppkt1->pkt->dts < 0)                        break;                    if(ppkt1->pkt->pts != AV_NOPTS_VALUE)                        break;                    ppkt1->pkt->dts -= delta;                    ppkt1= ppkt1->next;                }                if(ppkt1)                    continue;                st->cur_dts -= delta;            }        }    }#endif    return ret;}