From f06ec9ec92b0ec8f2961f34a4f047b5d4c225636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 17 Jul 2009 09:32:09 +0000 Subject: [PATCH] Fallback to detecting the stream duration from the AVFormatContext, if the AVStream does not provide it. For my test Flash Videos, I can at least get a duration now, although seeking is pretty broken. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31616 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/ffmpeg/AVFormatReader.cpp | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp index 10e64db98b..4f27a80d02 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp @@ -656,12 +656,24 @@ AVFormatReader::StreamCookie::GetStreamInfo(int64* frameCount, // for a couple of streams and are in line with the documentation, but // unfortunately, libavformat itself seems to set the time_base and // duration wrongly sometimes. :-( - TRACE(" stream duration: %lld, time_base %.4f (%d/%d)\n", - fStream->duration, - av_q2d(fStream->time_base), - fStream->time_base.num, fStream->time_base.den); - *duration = (bigtime_t)(1000000LL * fStream->duration - * av_q2d(fStream->time_base)); + static const int64 kNoPTSValue = 0x8000000000000000LL; + // NOTE: For some reasons, I have trouble with the avcodec.h define: + // #define AV_NOPTS_VALUE INT64_C(0x8000000000000000) + // INT64_C is not defined here. + if ((int64)fStream->duration != kNoPTSValue) { + *duration = (bigtime_t)(1000000LL * fStream->duration + * fStream->time_base.num / fStream->time_base.den); + TRACE(" stream duration: %lld, time_base %.4f (%d/%d)\n", + *duration, av_q2d(fStream->time_base), + fStream->time_base.num, fStream->time_base.den); + } else if ((int64)fContext->duration != kNoPTSValue) { + *duration = (bigtime_t)(1000000LL * fContext->duration / AV_TIME_BASE); + TRACE(" stream duration: %lld (from AVFormatContext)\n", + *duration); + } else { + *duration = 0; + TRACE(" stream duration: N/A\n"); + } TRACE(" duration: %lld or %.2fs\n", *duration, *duration / 1000000.0);