# HG changeset patch # User michael # Date 1103419402 0 # Node ID 7dbdbe073bcd0fcf1c6598e5682b9d89f1a9f10a # Parent 7d50b0a324ea366615452049daea13b9088aeeb4 try to guess the fps if they are variable diff -r 7d50b0a324ea -r 7dbdbe073bcd flvdec.c --- a/flvdec.c Fri Dec 17 19:23:53 2004 +0000 +++ b/flvdec.c Sun Dec 19 01:23:22 2004 +0000 @@ -103,7 +103,8 @@ return AVERROR_NOMEM; av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */ - st->codec.frame_rate_base= 0; + st->codec.frame_rate_base= 1; + st->codec.frame_rate= 1000; } break; } @@ -123,19 +124,12 @@ } } }else{ - if(st->codec.frame_rate_base == 0){ st->codec.codec_type = CODEC_TYPE_VIDEO; - //guess the frame rate - if(pts){ - st->codec.frame_rate_base=1; - st->codec.frame_rate= (1000 + pts/2)/pts; - } switch(flags & 0xF){ case 2: st->codec.codec_id = CODEC_ID_FLV1; break; default: st->codec.codec_tag= flags & 0xF; } - } } if (av_new_packet(pkt, size) < 0) diff -r 7d50b0a324ea -r 7dbdbe073bcd utils.c --- a/utils.c Fri Dec 17 19:23:53 2004 +0000 +++ b/utils.c Sun Dec 19 01:23:22 2004 +0000 @@ -1726,7 +1726,14 @@ AVStream *st; AVPacket pkt1, *pkt; AVPacketList *pktl=NULL, **ppktl; + int64_t last_dts[MAX_STREAMS]; + int64_t best_duration[MAX_STREAMS]; + for(i=0;ipacket_buffer; @@ -1792,6 +1799,15 @@ if (pkt->duration != 0) st->codec_info_nb_frames++; + if(st->codec.codec_type == CODEC_TYPE_VIDEO){ + int64_t last= last_dts[pkt->stream_index]; + + if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && last < pkt->dts && + best_duration[pkt->stream_index] > pkt->dts - last){ + best_duration[pkt->stream_index] = pkt->dts - last; + } + last_dts[pkt->stream_index]= pkt->dts; + } /* 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 @@ -1823,6 +1839,13 @@ if (st->codec.codec_type == CODEC_TYPE_VIDEO) { if(st->codec.codec_id == CODEC_ID_RAWVIDEO && !st->codec.codec_tag && !st->codec.bits_per_sample) st->codec.codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec.pix_fmt); + + if(best_duration[i] < INT64_MAX && st->codec.frame_rate_base*1000 <= st->codec.frame_rate){ + st->r_frame_rate= st->codec.frame_rate; + st->r_frame_rate_base= av_rescale(best_duration[i], st->codec.frame_rate, AV_TIME_BASE); + av_reduce(&st->r_frame_rate, &st->r_frame_rate_base, st->r_frame_rate, st->r_frame_rate_base, 1<<15); + } + /* set real frame rate info */ /* compute the real frame rate for telecine */ if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO ||