[FFmpeg-devel] [PATCH] Wrong duration in TS container (Ticket #1836)
Michael Niedermayer
michaelni at gmx.at
Thu Nov 15 13:54:41 CET 2012
Hi
On Sun, Nov 11, 2012 at 04:19:53PM +0900, Hee Suk Jung wrote:
>
> From 25afab03b00a822421d07da2330483809f179506 Mon Sep 17 00:00:00 2001
> From: Heesuk Jung <heesuk.jung at lge.com>
> Date: Sat, 10 Nov 2012 23:02:21 -0800
> Subject: [PATCH] Wrong duration in TS container (Ticket #1836)
>
> Sometimes TS container file has unreasonbly big PTS in last frame.
> In this case, we use previous last PTS value to decide stream dueation.
>
> Fix 2nd promlematic file cas in Ticket #1836
> link : https://docs.google.com/open?id=0B6r7ZfWFIypCNFVuWHowMFBBN0E
> ---
> libavformat/utils.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 0240b0c..6d953ed 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2157,6 +2157,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic)
>
> #define DURATION_MAX_READ_SIZE 250000LL
> #define DURATION_MAX_RETRY 4
> +#define DURATION_MULTIPLE_LIMIT 8
>
> /* only usable for MPEG-PS streams */
> static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
> @@ -2166,6 +2167,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
> int read_size, i, ret;
> int64_t end_time;
> int64_t filesize, offset, duration;
> + int64_t ref_duration, pre_duration;
> int retry=0;
>
> /* flush packet queue */
> @@ -2186,6 +2188,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
> /* XXX: may need to support wrapping */
> filesize = ic->pb ? avio_size(ic->pb) : 0;
> end_time = AV_NOPTS_VALUE;
> + i = 0;
> do{
> offset = filesize - (DURATION_MAX_READ_SIZE<<retry);
> if (offset < 0)
> @@ -2215,8 +2218,19 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
> if (duration < 0)
> duration += 1LL<<st->pts_wrap_bits;
> if (duration > 0) {
> - if (st->duration == AV_NOPTS_VALUE || st->duration < duration)
> + if (st->duration == AV_NOPTS_VALUE || st->duration < duration) {
> + pre_duration = st->duration;
> st->duration = duration;
> + i++;
> + if (i == 1) {
> + ref_duration = st->duration;
> + } else {
> + if (st->duration > ref_duration*DURATION_MULTIPLE_LIMIT) {
> + st->duration = pre_duration;
st->duration is in st->time_base units, 2 Streams can use different
time bases.
ref_duration*DURATION_MULTIPLE_LIMIT might theretically overflow,
better to divide or shift the other side of the comparission
setting ref_duration to 0 or AV_NOPTS_VALUE should avoid the need for
i
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121115/b265cb6b/attachment.asc>
More information about the ffmpeg-devel
mailing list