Mercurial > libavformat.hg
comparison utils.c @ 620:7dbdbe073bcd libavformat
try to guess the fps if they are variable
| author | michael |
|---|---|
| date | Sun, 19 Dec 2004 01:23:22 +0000 |
| parents | 65787cd808e4 |
| children | e7b64333f116 |
comparison
equal
deleted
inserted
replaced
| 619:7d50b0a324ea | 620:7dbdbe073bcd |
|---|---|
| 1724 { | 1724 { |
| 1725 int i, count, ret, read_size; | 1725 int i, count, ret, read_size; |
| 1726 AVStream *st; | 1726 AVStream *st; |
| 1727 AVPacket pkt1, *pkt; | 1727 AVPacket pkt1, *pkt; |
| 1728 AVPacketList *pktl=NULL, **ppktl; | 1728 AVPacketList *pktl=NULL, **ppktl; |
| 1729 | 1729 int64_t last_dts[MAX_STREAMS]; |
| 1730 int64_t best_duration[MAX_STREAMS]; | |
| 1731 | |
| 1732 for(i=0;i<MAX_STREAMS;i++){ | |
| 1733 last_dts[i]= AV_NOPTS_VALUE; | |
| 1734 best_duration[i]= INT64_MAX; | |
| 1735 } | |
| 1736 | |
| 1730 count = 0; | 1737 count = 0; |
| 1731 read_size = 0; | 1738 read_size = 0; |
| 1732 ppktl = &ic->packet_buffer; | 1739 ppktl = &ic->packet_buffer; |
| 1733 for(;;) { | 1740 for(;;) { |
| 1734 /* check if one codec still needs to be handled */ | 1741 /* check if one codec still needs to be handled */ |
| 1790 st = ic->streams[pkt->stream_index]; | 1797 st = ic->streams[pkt->stream_index]; |
| 1791 st->codec_info_duration += pkt->duration; | 1798 st->codec_info_duration += pkt->duration; |
| 1792 if (pkt->duration != 0) | 1799 if (pkt->duration != 0) |
| 1793 st->codec_info_nb_frames++; | 1800 st->codec_info_nb_frames++; |
| 1794 | 1801 |
| 1802 if(st->codec.codec_type == CODEC_TYPE_VIDEO){ | |
| 1803 int64_t last= last_dts[pkt->stream_index]; | |
| 1804 | |
| 1805 if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && last < pkt->dts && | |
| 1806 best_duration[pkt->stream_index] > pkt->dts - last){ | |
| 1807 best_duration[pkt->stream_index] = pkt->dts - last; | |
| 1808 } | |
| 1809 last_dts[pkt->stream_index]= pkt->dts; | |
| 1810 } | |
| 1795 /* if still no information, we try to open the codec and to | 1811 /* if still no information, we try to open the codec and to |
| 1796 decompress the frame. We try to avoid that in most cases as | 1812 decompress the frame. We try to avoid that in most cases as |
| 1797 it takes longer and uses more memory. For MPEG4, we need to | 1813 it takes longer and uses more memory. For MPEG4, we need to |
| 1798 decompress for Quicktime. */ | 1814 decompress for Quicktime. */ |
| 1799 if (!has_codec_parameters(&st->codec) && | 1815 if (!has_codec_parameters(&st->codec) && |
| 1821 for(i=0;i<ic->nb_streams;i++) { | 1837 for(i=0;i<ic->nb_streams;i++) { |
| 1822 st = ic->streams[i]; | 1838 st = ic->streams[i]; |
| 1823 if (st->codec.codec_type == CODEC_TYPE_VIDEO) { | 1839 if (st->codec.codec_type == CODEC_TYPE_VIDEO) { |
| 1824 if(st->codec.codec_id == CODEC_ID_RAWVIDEO && !st->codec.codec_tag && !st->codec.bits_per_sample) | 1840 if(st->codec.codec_id == CODEC_ID_RAWVIDEO && !st->codec.codec_tag && !st->codec.bits_per_sample) |
| 1825 st->codec.codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec.pix_fmt); | 1841 st->codec.codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec.pix_fmt); |
| 1842 | |
| 1843 if(best_duration[i] < INT64_MAX && st->codec.frame_rate_base*1000 <= st->codec.frame_rate){ | |
| 1844 st->r_frame_rate= st->codec.frame_rate; | |
| 1845 st->r_frame_rate_base= av_rescale(best_duration[i], st->codec.frame_rate, AV_TIME_BASE); | |
| 1846 av_reduce(&st->r_frame_rate, &st->r_frame_rate_base, st->r_frame_rate, st->r_frame_rate_base, 1<<15); | |
| 1847 } | |
| 1848 | |
| 1826 /* set real frame rate info */ | 1849 /* set real frame rate info */ |
| 1827 /* compute the real frame rate for telecine */ | 1850 /* compute the real frame rate for telecine */ |
| 1828 if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO || | 1851 if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO || |
| 1829 st->codec.codec_id == CODEC_ID_MPEG2VIDEO) && | 1852 st->codec.codec_id == CODEC_ID_MPEG2VIDEO) && |
| 1830 st->codec.sub_id == 2) { | 1853 st->codec.sub_id == 2) { |
