Mercurial > libavformat.hg
comparison utils.c @ 1755:41160bae24b5 libavformat
Fix audio corruption when cutting.
Patch by Wolfram Gloger, wmglo dent dot med dot uni-muenchen dot de.
author | takis |
---|---|
date | Mon, 05 Feb 2007 02:08:57 +0000 |
parents | b1fb0af4387a |
children | 5d72afc6c8aa |
comparison
equal
deleted
inserted
replaced
1754:1f7a6dc01100 | 1755:41160bae24b5 |
---|---|
1556 } | 1556 } |
1557 | 1557 |
1558 #define DURATION_MAX_READ_SIZE 250000 | 1558 #define DURATION_MAX_READ_SIZE 250000 |
1559 | 1559 |
1560 /* only usable for MPEG-PS streams */ | 1560 /* only usable for MPEG-PS streams */ |
1561 static void av_estimate_timings_from_pts(AVFormatContext *ic) | 1561 static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offset) |
1562 { | 1562 { |
1563 AVPacket pkt1, *pkt = &pkt1; | 1563 AVPacket pkt1, *pkt = &pkt1; |
1564 AVStream *st; | 1564 AVStream *st; |
1565 int read_size, i, ret; | 1565 int read_size, i, ret; |
1566 int64_t end_time; | 1566 int64_t end_time; |
1648 av_free_packet(pkt); | 1648 av_free_packet(pkt); |
1649 } | 1649 } |
1650 | 1650 |
1651 fill_all_stream_timings(ic); | 1651 fill_all_stream_timings(ic); |
1652 | 1652 |
1653 url_fseek(&ic->pb, 0, SEEK_SET); | 1653 url_fseek(&ic->pb, old_offset, SEEK_SET); |
1654 } | 1654 } |
1655 | 1655 |
1656 static void av_estimate_timings(AVFormatContext *ic) | 1656 static void av_estimate_timings(AVFormatContext *ic, offset_t old_offset) |
1657 { | 1657 { |
1658 int64_t file_size; | 1658 int64_t file_size; |
1659 | 1659 |
1660 /* get the file size, if possible */ | 1660 /* get the file size, if possible */ |
1661 if (ic->iformat->flags & AVFMT_NOFILE) { | 1661 if (ic->iformat->flags & AVFMT_NOFILE) { |
1669 | 1669 |
1670 if ((!strcmp(ic->iformat->name, "mpeg") || | 1670 if ((!strcmp(ic->iformat->name, "mpeg") || |
1671 !strcmp(ic->iformat->name, "mpegts")) && | 1671 !strcmp(ic->iformat->name, "mpegts")) && |
1672 file_size && !ic->pb.is_streamed) { | 1672 file_size && !ic->pb.is_streamed) { |
1673 /* get accurate estimate from the PTSes */ | 1673 /* get accurate estimate from the PTSes */ |
1674 av_estimate_timings_from_pts(ic); | 1674 av_estimate_timings_from_pts(ic, old_offset); |
1675 } else if (av_has_timings(ic)) { | 1675 } else if (av_has_timings(ic)) { |
1676 /* at least one components has timings - we use them for all | 1676 /* at least one components has timings - we use them for all |
1677 the components */ | 1677 the components */ |
1678 fill_all_stream_timings(ic); | 1678 fill_all_stream_timings(ic); |
1679 } else { | 1679 } else { |
1763 if(i<60*12) return i*1001; | 1763 if(i<60*12) return i*1001; |
1764 else return ((int[]){24,30,60,12,15})[i-60*12]*1000*12; | 1764 else return ((int[]){24,30,60,12,15})[i-60*12]*1000*12; |
1765 } | 1765 } |
1766 | 1766 |
1767 /** | 1767 /** |
1768 * Read the beginning of a media file to get stream information. This | 1768 * Read packets of a media file to get stream information. This |
1769 * is useful for file formats with no headers such as MPEG. This | 1769 * is useful for file formats with no headers such as MPEG. This |
1770 * function also compute the real frame rate in case of mpeg2 repeat | 1770 * function also computes the real frame rate in case of mpeg2 repeat |
1771 * frame mode. | 1771 * frame mode. |
1772 * The logical file position is not changed by this function; | |
1773 * examined packets may be buffered for later processing. | |
1772 * | 1774 * |
1773 * @param ic media file handle | 1775 * @param ic media file handle |
1774 * @return >=0 if OK. AVERROR_xxx if error. | 1776 * @return >=0 if OK. AVERROR_xxx if error. |
1775 * @todo let user decide somehow what information is needed so we dont waste time geting stuff the user doesnt need | 1777 * @todo let user decide somehow what information is needed so we dont waste time geting stuff the user doesnt need |
1776 */ | 1778 */ |
1781 AVPacket pkt1, *pkt; | 1783 AVPacket pkt1, *pkt; |
1782 AVPacketList *pktl=NULL, **ppktl; | 1784 AVPacketList *pktl=NULL, **ppktl; |
1783 int64_t last_dts[MAX_STREAMS]; | 1785 int64_t last_dts[MAX_STREAMS]; |
1784 int duration_count[MAX_STREAMS]={0}; | 1786 int duration_count[MAX_STREAMS]={0}; |
1785 double duration_error[MAX_STREAMS][MAX_STD_TIMEBASES]={{0}}; //FIXME malloc()? | 1787 double duration_error[MAX_STREAMS][MAX_STD_TIMEBASES]={{0}}; //FIXME malloc()? |
1788 offset_t old_offset = url_ftell(&ic->pb); | |
1786 | 1789 |
1787 for(i=0;i<ic->nb_streams;i++) { | 1790 for(i=0;i<ic->nb_streams;i++) { |
1788 st = ic->streams[i]; | 1791 st = ic->streams[i]; |
1789 if(st->codec->codec_type == CODEC_TYPE_VIDEO){ | 1792 if(st->codec->codec_type == CODEC_TYPE_VIDEO){ |
1790 /* if(!st->time_base.num) | 1793 /* if(!st->time_base.num) |
1987 } | 1990 } |
1988 } | 1991 } |
1989 } | 1992 } |
1990 } | 1993 } |
1991 | 1994 |
1992 av_estimate_timings(ic); | 1995 av_estimate_timings(ic, old_offset); |
1993 #if 0 | 1996 #if 0 |
1994 /* correct DTS for b frame streams with no timestamps */ | 1997 /* correct DTS for b frame streams with no timestamps */ |
1995 for(i=0;i<ic->nb_streams;i++) { | 1998 for(i=0;i<ic->nb_streams;i++) { |
1996 st = ic->streams[i]; | 1999 st = ic->streams[i]; |
1997 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { | 2000 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |