From 2e39befd7c949c0ae0cbb919e799aada276b46e0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Jan 2022 17:17:12 +0300 Subject: [PATCH] Don't trust AVFormatContext duration in Webm video. It reports some strange numbers like 1000, which is 1ms. --- .../media/streaming/media_streaming_file.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_file.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_file.cpp index 92f49e831..535e8b9c8 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_file.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_file.cpp @@ -18,6 +18,18 @@ namespace { constexpr auto kMaxSingleReadAmount = 8 * 1024 * 1024; constexpr auto kMaxQueuedPackets = 1024; +[[nodiscard]] bool UnreliableFormatDuration( + not_null format, + not_null stream) { + return stream->codec + && (stream->codec->codec_id == AV_CODEC_ID_VP9) + && format->iformat + && format->iformat->name + && QString::fromLatin1( + format->iformat->name + ).split(QChar(',')).contains(u"webm"); +} + } // namespace File::Context::Context( @@ -174,6 +186,8 @@ Stream File::Context::initStream( result.timeBase = info->time_base; result.duration = (info->duration != AV_NOPTS_VALUE) ? FFmpeg::PtsToTime(info->duration, result.timeBase) + : UnreliableFormatDuration(format, info) + ? kTimeUnknown : FFmpeg::PtsToTime(format->duration, FFmpeg::kUniversalTimeBase); if (result.duration == kTimeUnknown) { result.duration = kDurationUnavailable;